Pyrite is the most common of sulfide minerals and is widespread in igneous, metamorphic, and sedimentary rocks. It is a common accessory mineral in igneous rocks, where it also occasionally occurs as larger masses arising from an immiscible sulfide phase in the original magma. It is found in metamorphic rocks as a product of contact metamorphism. It also forms as a high-temperature hydrothermal mineral, though it occasionally forms at lower temperatures.
Pyrite occurs both as a primary mineral, present in the original sediments, and as a secondary mineral, deposited during diagenesis. Pyrite and marcasite commonly occur as replacement pseudomorphs after fossils in black shale and other sedimentary rocks formed under reducing environmental conditions. Pyrite is common as an accessory mineral in shale, where it is formed by precipitation from anoxic seawater, and coal beds often contain significant pyrite.
Notable deposits are found as lenticular masses in Virginia, U.S., and in smaller quantities in many other locations. Large deposits are mined at Rio Tinto in Spain and elsewhere in the Iberian Peninsula.