Methanogens inhabit euxinic (sulfide-rich) or ferruginous (iron-rich) environments that promote the precipitation of transition metals as metal sulfides, such as pyrite, reducing metal or sulfur availability. Such environments have been common throughout Earth’s history raising the question as to how anaerobes obtain(ed) these elements for the synthesis of enzyme cofactors. Here, we show a methanogen can synthesize molybdenum nitrogenase metallocofactors from pyrite as the source of iron and sulfur, enabling nitrogen fixation. Pyrite-grown, nitrogen-fixing cells grow faster and require 25-fold less molybdenum than cells grown under euxinic conditions. Growth yields are 3 to 8 times higher in cultures grown under ferruginous relative to euxinic conditions. Physiological, transcriptomic, and geochemical data indicate these observations are due to sulfide-promoted metal limitation, in particular molybdenum. These findings suggest that molybdenum nitrogenase may have originated in a ferruginous environment that titrated sulfide to form pyrite, facilitating the availability of sufficient iron, sulfur, and molybdenum for cofactor biosynthesis.