We report resonantly enhanced and switchable third order nonlinearity in magnesium thin films. Utilizing an optical parametric oscillator as a tunable broadband light source, we find a highly wavelength dependent third harmonic conversion efficiency, exhibiting a 40-to 50-fold signal increase over the investigated wavelength range between 1300 and 1800 nm. We relate this unusually strong increase of the intrinsic magnesium material nonlinearity to resonant sp-interband transitions around 0.7 eV or 1770 nm in the fundamental wavelength range, multiplying their impact on the conversion efficiencies. Moreover, we make use of the drastic change in the optical properties of magnesium at the phase transition between metallic magnesium and dielectric magnesium hydride by in situ hydrogenation. We are able to cyclically switch the nonlinearity and the efficiency of the third harmonic conversion process. The time-dependence of the nonlinear signal is complex and is a consequence of several contributions, including the hydrogen concentration-dependent change in the intrinsic nonlinear susceptibility, the change in the surface morphology during hydrogenation and dehydrogenation, as well as the volume change of the material. While shedding new light on the structural and morphological changes in such magnesium thin films, we envision that the switchable and large resonant third-order nonlinearity in magnesium will find applications in nanostructured systems, unlocking additional degrees of freedom in design and implementation, such as wavelength dependency and switchable material nonlinearities.