The nematode Caenorhabditis elegans has complex, naturally variable behavioral responses to environmental oxygen, food, and other animals. C. elegans detects oxygen through soluble guanylate cyclase homologs (sGCs) and responds to it differently depending on the activity of the neuropeptide receptor NPR-1: npr-1(If) and naturally isolated npr-1(215F) animals avoid high oxygen and aggregate in the presence of food; npr-1(215V) animals do not. We show here that hyperoxia avoidance integrates food with npr-1 activity through neuromodulation of a distributed oxygen-sensing network. Hyperoxia avoidance is stimulated by sGC-expressing oxygen-sensing neurons, nociceptive neurons, and ADF sensory neurons. In npr-1(215V) animals, the switch from weak aerotaxis on food to strong aerotaxis in its absence requires close regulation of the neurotransmitter serotonin in the ADF neurons; high levels of ADF serotonin promote hyperoxia avoidance. In npr-1(If) animals, food regulation is masked by increased activity of the oxygen-sensing neurons. Hyperoxia avoidance is also regulated by the neuronal TGF-beta homolog DAF-7, a secreted mediator of crowding and stress responses. DAF-7 inhibits serotonin synthesis in ADF, suggesting that ADF serotonin is a convergence point for regulation of hyperoxia avoidance. Coalitions of neurons that promote and repress hyperoxia avoidance generate a subtle and flexible response to environmental oxygen.