The Caenorhabditis elegans defecation motor program (DMP) is a highly coordinated rhythmic behavior that requires two GABAergic neurons that synapse onto the enteric muscles. One class of DMP mutants, called anterior body wall muscle contraction and expulsion defective (aex) mutants, exhibits similar defects to those caused by the loss of these two neurons. Here, we demonstrate that aex-2 encodes a G-protein-coupled receptor (GPCR) and aex-4 encodes an exocytic SNAP25 homologue. We found that aex-2 functions in the nervous system and activates a G(s)alpha signaling pathway to regulate defecation. aex-4, on the other hand, functions in the intestinal epithelial cells. Furthermore, we show that aex-5, which encodes a pro-protein convertase, functions in the intestine to regulate the DMP and that its secretion from the intestine is impaired in aex-4 mutants. Activation of the G(s)alpha GPCR pathway in GABAergic neurons can suppress the defecation defect of the intestinal mutants aex-4 and aex-5. Lastly, we demonstrate that activation of GABAergic neurons using the light-gated cation channel channelrhodopsin-2 is sufficient to suppress the behavioral defects of aex-2, aex-4, and aex-5. These results genetically place intestinal genes aex-4 and aex-5 upstream of GABAergic GPCR signaling. We propose a model whereby the intestinal genes aex-4 and aex-5 control the DMP by regulating the secretion of a signal, which activates the neuronal receptor aex-2.