Serotonin has been implicated in the regulation of a wide range of brain functions involving alternative behavioral states, including the control of mood, aggression, sex, and sleep. Here, we report that in the nematode Caenorhabditis elegans, serotonin controls a switch between two distinct, on/off states of egg-laying behavior. Through quantitative analysis of the temporal pattern of egg-laying events, we determined that egg laying can be modeled as a novel random process, in which animals fluctuate between discrete behavioral states: an active state, during which eggs are laid in clusters, and an inactive state, during which eggs are retained. Single-cell ablation experiments indicate that two pairs of motor neurons, HSNL/HSNR and VC4/VC5, can induce the active phase by releasing serotonin. These neurons also release acetylcholine, which appears to trigger individual egg-laying events within the active phase. Genetic experiments suggest that determination of the behavioral states observed for C. elegans egg laying may be mediated through protein kinase C-dependent (PKC-dependent) modulation of voltage-gated calcium channels.