Many nematodes show a stage-specific behavior called nictation in which a worm stands on its tail and waves its head in three dimensions. Here we show that nictation is a dispersal behavior regulated by a specific set of neurons, the IL2 cells, in C. elegans. We established assays for nictation and showed that cholinergic transmission was required for nictation. Cell type-specific rescue experiments and genetic ablation experiments revealed that the IL2 ciliated head neurons were essential for nictation. Intact cilia in IL2 neurons, but not in other ciliated head neurons, were essential, as the restoration of the corresponding wild-type gene activity in IL2 neurons alone in cilia-defective mutants was sufficient to restore nictation. Optogenetic activation of IL2 neurons induced nictation, suggesting that signals from IL2 neurons are sufficient for nictation. Finally, we demonstrated that nictation is required for transmission of C. elegans to a new niche using flies as artificial carriers, suggesting a role of nictation as a dispersal and survival strategy under harsh conditions.