Starting from the Dirac-Kohn-Sham equation we derive the relativistic equation of motion of spin angular momentum in a magnetic solid under an external electromagnetic field. This equation of motion can be rewritten in the form of the well-known Landau-Lifshitz-Gilbert equation for a harmonic external magnetic field, and leads to a more general magnetization dynamics equation for a general time-dependent magnetic field. In both cases with an electronic spin-relaxation term which stems from the spin-orbit interaction. We thus rigorously derive, from fundamental principles, a general expression for the anisotropic damping tensor which is shown to contain an isotropic Gilbert contribution as well as an anisotropic Ising-like and a chiral, Dzyaloshinskii-Moriya-like contribution. The expression for the spin relaxation tensor comprises furthermore both electronic interband and intraband transitions. We also show that when the externally applied electromagnetic field possesses spin angular momentum, this will lead to an optical spin torque exerted on the spin moment.