Pacemaker neurons exert control over neuronal circuit function by their intrinsic ability to generate rhythmic bursts of action potential. Recent work has identified rhythmic gut contractions in human, mice, and hydra to be dependent on both neurons and the resident microbiota. However, little is known about the evolutionary origin of these neurons and their interaction with microbes. In this study, we identified and functionally characterized prototypical ANO/SCN/TRPM ion channel-expressing pacemaker cells in the basal metazoan Hydra by using a combination of single-cell transcriptomics, immunochemistry, and functional experiments. Unexpectedly, these prototypical pacemaker neurons express a rich set of immune-related genes mediating their interaction with the microbial environment. Furthermore, functional experiments gave a strong support to a model of the evolutionary emergence of pacemaker cells as neurons using components of innate immunity to interact with the microbial environment and ion channels to generate rhythmic contractions.