Small molecules containing the N-nitroso group, such as the bacterial natural product streptozotocin, are prominent carcinogens1,2 and important cancer chemotherapeutics3,4. Despite the considerable importance of this functional group to human health, enzymes dedicated to the assembly of the N-nitroso unit have not been identified. Here we show that SznF, a metalloenzyme from the biosynthesis of streptozotocin, catalyses an oxidative rearrangement of the guanidine group of Nω-methyl-l-arginine to generate an N-nitrosourea product. Structural characterization and mutagenesis of SznF reveal two separate active sites that promote distinct steps in this transformation using different iron-containing metallocofactors. This biosynthetic reaction, which has little precedent in enzymology or organic synthesis, expands the catalytic capabilities of non-haem-iron-dependent enzymes to include N-N bond formation. We find that biosynthetic gene clusters that encode SznF homologues are widely distributed among bacteria—including environmental organisms, plant symbionts and human pathogens—which suggests an unexpectedly diverse and uncharacterized microbial reservoir of bioactive N-nitroso metabolites.