Cells organize and regulate their metabolism via membrane- or protein-bound organelles. In this way, incompatible processes can be spatially separated and controlled. In prokaryotes, protein-based compartments are used to sequester harmful reactions and store useful compounds. These protein compartments play key roles in various metabolic and ecological processes ranging from iron homeostasis to carbon fixation. We identified more than 900 proteinaceous encapsulin nanocompartment systems in bacterial and archaeal genomes. Encapsulins can be found in 15 bacterial and 2 archaeal phyla. Our analysis reveals 1 new capsid type and 9 previously unknown cargo proteins targeted to the interior of encapsulins. We experimentally characterize 3 newly identified encapsulin systems and illustrate their involvement in iron mineralization, oxidative and nitrosative stress resistance and anaerobic ammonium oxidation, a process responsible for 30% of the N lost from the oceans. We propose that encapsulins represent a widespread strategy for toxic reaction sequestration in prokaryotes.