Neural control of the function of visceral organs is essential for homeostasis and health. Intestinal peristalsis is critical for digestive physiology and host defence, and is often dysregulated in gastrointestinal disorders1. Luminal factors, such as diet and microbiota, regulate neurogenic programs of gut motility2-5, but the underlying molecular mechanisms remain unclear. Here we show that the transcription factor aryl hydrocarbon receptor (AHR) functions as a biosensor in intestinal neural circuits, linking their functional output to the microbial environment of the gut lumen. Using nuclear RNA sequencing of mouse enteric neurons that represent distinct intestinal segments and microbiota states, we demonstrate that the intrinsic neural networks of the colon exhibit unique transcriptional profiles that are controlled by the combined effects of host genetic programs and microbial colonization. Microbiota-induced expression of AHR in neurons of the distal gastrointestinal tract enables these neurons to respond to the luminal environment and to induce expression of neuron-specific effector mechanisms. Neuron-specific deletion of Ahr, or constitutive overexpression of its negative feedback regulator CYP1A1, results in reduced peristaltic activity of the colon, similar to that observed in microbiota-depleted mice. Finally, expression of Ahr in the enteric neurons of mice treated with antibiotics partially restores intestinal motility. Together, our experiments identify AHR signalling in enteric neurons as a regulatory node that integrates the luminal environment with the physiological output of intestinal neural circuits to maintain gut homeostasis and health.