Leak potassium (K<sup>+</sup>) currents, conducted by two-pore domain K<sup>+</sup> (K<sub>2P</sub>) channels, are critical for the stabilization of the membrane potential. The effect of K<sub>2P</sub> channels on motor rhythm remains enigmatic. We show here that the K<sub>2P</sub> TWK-40 contributes to the rhythmic defecation motor program (DMP) in <i>Caenorhabditis elegans</i>. Disrupting TWK-40 suppresses the expulsion defects of <i>
nlp-40</i> and <i>
aex-2</i> mutants. By contrast, a gain-of-function (<i>gf</i>) mutant of <i>
twk-40</i> significantly reduces the expulsion frequency per DMP cycle. In situ whole-cell patch clamping demonstrates that TWK-40 forms an outward current that hyperpolarize the resting membrane potential of dorsorectal ganglion ventral process B (DVB), an excitatory GABAergic motor neuron that activates expulsion muscle contraction. In addition, TWK-40 substantially contributes to the rhythmic activity of DVB. Specifically, DVB Ca<sup>2+</sup> oscillations exhibit obvious defects in loss-of-function (<i>lf</i>) mutant of <i>
twk-40</i>. Expression of TWK-40(<i>gf</i>) in DVB recapitulates the expulsion deficiency of the <i>
twk-40(gf)</i> mutant, and inhibits DVB Ca<sup>2+</sup> oscillations in both wild-type and <i>
twk-40(lf)</i> animals. Moreover, DVB innervated enteric muscles also exhibit rhythmic Ca<sup>2+</sup> defects in <i>
twk-40</i> mutants. In summary, these findings establish TWK-40 as a crucial neuronal stabilizer of DMP, linking leak K<sub>2P</sub> channels with rhythmic motor activity.