Spontaneous emission of radiation is one of the fundamental mechanisms by which an excited quantum system returns to equilibrium. For spins, however, spontaneous emission is generally negligible compared to other non-radiative relaxation processes because of the weak coupling between the magnetic dipole and the electromagnetic field. In 1946, Purcell realized1 that the rate of spontaneous emission can be greatly enhanced by placing the quantum system in a resonant cavity. This effect has since been used extensively to control the lifetime of atoms and semiconducting heterostructures coupled to microwave2 or optical3,4 cavities, and is essential for the realization of high-efficiency single-photon sources5. Here we report the application of this idea to spins in solids. By coupling donor spins in silicon to a superconducting microwave cavity with a high quality factor and a small mode volume, we reach the regime in which spontaneous emission constitutes the dominant mechanism of spin relaxation. The relaxation rate is increased by three orders of magnitude as the spins are tuned to the cavity resonance, demonstrating that energy relaxation can be controlled on demand. Our results provide a general way to initialize spin systems into their ground state and therefore have applications in magnetic resonance and quantum information processing6. They also demonstrate that the coupling between the magnetic dipole of a spin and the electromagnetic field can be enhanced up to the point at which quantum fluctuations have a marked effect on the spin dynamics; as such, they represent an important step towards the coherent magnetic coupling of individual spins to microwave photons.