We present a formulation of nonadiabatic dynamics "on the fly" combining time-dependent density functional theory using localized Gaussian basis sets with Tully's stochastic fewest switches surface hopping procedure. The aim is to provide a suitable approach for studying ultrafast photoincluced dynamics over a manifold of excited states in complex systems based on semiclassical dynamics, which takes into account all nuclear degrees of freedom. The reliability of the approach has been illustrated on the example of photodynamics in pyrazine by carrying out nonadiabatic dynamics over four excited electronic states. The calculated nonradiative lifetime of the optically allowed S-2 state of 20 fs is in a good agreement with the results obtained from full quantum dynamical treatment and with available experimental data. Our simulated time-resolved photoelectron spectrum of pyrazine represents the observable which can be experimentally measured providing the time scales of nonadiabatic processes. Therefore, the presented theoretical results should stimulate the experimental work in the future. (c) 2008 Elsevier B.V. All rights reserved.