  A detailed derivation of the recently proposed time-dependent numerical
renormalization-group (TD-NRG) approach to nonequilibrium dynamics in quantum
impurity systems is presented. We demonstrate that the method is suitable for
fermionic as well as bosonic baths. A comparison with exact analytical results
for the charge relaxation in the resonant-level model and for dephasing in the
spin-boson model establishes the accuracy of the method. The real-time dynamics
of a single spin coupled to both types of baths is investigated. We use the
TD-NRG to calculate the spin relaxation and spin precession of a single Kondo
impurity. The short- and long-time dynamics is studied as a function of
temperature in the ferromagnetic and antiferromagnetic regimes. The short-time
dynamics agrees very well with analytical results obtained at second order in
the exchange coupling $J$. In the ferromagnetic regime, the long-time spin
decay is described by the scaling variable $x = 2\rho_F J(T) T t$. In the
antiferromagnetic regime it is governed for $T < T_K$ by the Kondo time scale
$1/T_K$. Here $\rho_F$ is the conduction-electron density of states and $T_K$
is the Kondo temperature. Results for spin precession are obtained by rotating
the external magnetic field from the x axis to the z axis.
