In this work, we derive a method to perform trajectory-based nonadiabatic dynamics that is able to describe both nonadiabatic transitions and intersystem crossing events (transitions between states of different spin-multiplicity) at the same level of theory, namely, time-dependent density functional theory (TDDFT). To this end, we combined our previously developed TDDFT-based trajectory surface hopping scheme with an accurate and efficient algorithm for the calculation of the spin-orbit coupling (SOC) matrix elements. More specifically, we designed two algorithms for the calculation of intersystem crossing transitions, one based on an extended Tully's surface hopping scheme including SOC and the second based on a Landau-Zener approximation applied to the spin sector of the electronic Hilbert space. This development allows for the design of an efficient on-the-fly nonadiabatic approach that can handle, on an equal footing, nonadiabatic and intersystem crossing transitions. The method is applied to the study of the photophysics of sulfur dioxide (SO2) in gas and liquid phases.