Behavioral plasticity is widespread in swarming animals, but little is known about its underlying neural and molecular mechanisms. Here, we report that a neuropeptide F (NPF)/nitric oxide (NO) pathway plays a critical role in the locomotor plasticity of swarming migratory locusts. The transcripts encoding two related neuropeptides, NPF1a and NPF2, show reduced levels during crowding, and the transcript levels of NPF1a and NPF2 receptors significantly increase during locust isolation. Both NPF1a and NPF2 have suppressive effects on phase-related locomotor activity. A key downstream mediator for both NPFs is nitric oxide synthase (NOS), which regulates phase-related locomotor activity by controlling NO synthesis in the locust brain. Mechanistically, NPF1a and NPF2 modify NOS activity by separately suppressing its phosphorylation and by lowering its transcript level, effects that are mediated by their respective receptors. Our results uncover a hierarchical neurochemical mechanism underlying behavioral plasticity in the swarming locust and provide insights into the NPF/NO axis.