Many animals, including humans, select alternate forms of motion (gaits) to move efficiently in different environments. However, it is unclear whether primitive animals, such as nematodes, also use this strategy. We used a multifaceted approach to study how the nematode Caenorhabditis elegans freely moves into and out of water. We demonstrate that C. elegans uses biogenic amines to switch between distinct crawling and swimming gaits. Dopamine is necessary and sufficient to initiate and maintain crawling after swimming. Serotonin is necessary and sufficient to transition from crawling to swimming and to inhibit a set of crawl-specific behaviors. Further study of locomotory switching in C. elegans and its dependence on biogenic amines may provide insight into how gait transitions are performed in other animals.