A transient analysis in time domain of beam-wave interaction for gyroklystron is made with self-consistent field theory. A nonlinear theory for gyroklystron with multiple cavities is then established, and corresponding electron motion equations and transient electromagnetic field equations with a complex form are given. For a Ka-band gyroklystron with four cavities, some numerical results of beam-wave interaction are given and analyzed. A saturated output power of 335 kW, corresponding to efficiency of 39.6% and saturated bandwidth of 320 MHz is achieved with a 72.8 kV, 11.8 A electron beam in TE01 mode when the speed spread is 5%. The numerical results agree well with the experimental data.