The nitrogen in lunar soils is correlated to the surface and therefore clearly implanted from outside. The straightforward interpretation is that the nitrogen is implanted by the solar wind, but this explanation has difficulties accounting for both the abundance of nitrogen and a variation of the order of 30 per cent in the 15N/14N ratio. Here we propose that most of the nitrogen and some of the other volatile elements in lunar soils may actually have come from the Earth's atmosphere rather than the solar wind. We infer that this hypothesis is quantitatively reasonable if the escape of atmospheric gases, and implantation into lunar soil grains, occurred at a time when the Earth had essentially no geomagnetic field. Thus, evidence preserved in lunar soils might be useful in constraining when the geomagnetic field first appeared. This hypothesis could be tested by examination of lunar farside soils, which should lack the terrestrial component.