Defecation allows the body to eliminate waste, an essential step in food processing for animal survival. In contrast to the extensive studies of feeding, its obligate counterpart, defecation, has received much less attention until recently. In this study, we report our characterizations of the defecation behavior of Drosophila larvae and its neural basis. Drosophila larvae display defecation cycles of stereotypic frequency, involving sequential contraction of hindgut and anal sphincter. The defecation behavior requires two groups of motor neurons that innervate hindgut and anal sphincter, respectively, and can excite gut muscles directly. These two groups of motor neurons fire sequentially with the same periodicity as the defecation behavior, as revealed by in vivo Ca(2+) imaging. Moreover, we identified a single mechanosensitive sensory neuron that innervates the anal slit and senses the opening of the intestine terminus. This anus sensory neuron relies on the TRP channel NOMPC but not on INACTIVE, NANCHUNG, or PIEZO for mechanotransduction.