To analyze mechanisms that modulate serotonin signaling, we investigated how Caenorhabditis elegans regulates the function of serotonergic motor neurons that stimulate egg-laying behavior. Egg laying is inhibited by the G protein Galphao and activated by the G protein Galphaq. We found that Galphao and Galphaq act directly in the serotonergic HSN motor neurons to control egg laying. There, the G proteins had opposing effects on transcription of the tryptophan hydroxylase gene tph-1, which encodes the rate-limiting enzyme for serotonin biosynthesis. Antiserotonin staining confirmed that Galphao and Galphaq antagonistically affect serotonin levels. Altering tph-1 gene dosage showed that small changes in tph-1 expression were sufficient to affect egg-laying behavior. Epistasis experiments showed that signaling through the G proteins has additional tph-1-independent effects. Our results indicate that (1) serotonin signaling is regulated by modulating serotonin biosynthesis and (2) Galphao and Galphaq act in the same neurons to have opposing effects on behavior, in part, by antagonistically regulating transcription of specific genes. Galphao and Galphaq have opposing effects on many behaviors in addition to egg laying and may generally act, as they do in the egg-laying system, to integrate multiple signals and consequently set levels of transcription of genes that affect neurotransmitter release.