Anaerobic metabolisms are thought to dominate nitrogen cycling in anoxic marine zones (AMZs). However, thriving populations of aerobic nitrite-oxidizing bacteria (NOB) in AMZs challenge this assumption and remain unexplained. Using theory and modelling, we show how periodic oxygen intrusions sustain aerobic NOB in AMZs alongside more competitive aerobic heterotrophs. Ecological theory, supported by numerical simulations and genomics, frames NOB as opportunists exploiting a fleeting supply of oxygen. Consistent with in situ observations, simulated NOB contribute substantially to total oxygen consumption at AMZ boundaries, which implies that NOB may provide a major stabilizing feedback to AMZs. Fine-scale ocean currents increase the metabolic diversity in AMZs, which could stabilize AMZ volume under climate change.