Negative psychological states impact immunity by altering the gut microbiome. However, the relationship between brain states and microbiome composition remains unclear. We show that Brunner's glands in the duodenum couple stress-sensitive brain circuits to bacterial homeostasis. Brunner's glands mediated the enrichment of gut Lactobacillus species in response to vagus nerve stimulation. Cell-specific ablation of the glands markedly suppressed Lactobacilli counts and heightened vulnerability to infection. In the forebrain, we mapped a vagally mediated, polysynaptic circuit connecting the central nucleus of the amygdala to Brunner's glands. Chronic stress suppressed central amygdala activity and phenocopied the effects of gland lesions. Conversely, excitation of either the central amygdala or parasympathetic vagal neurons activated Brunner's glands and reversed the effects of stress on the gut microbiome and immunity. The findings revealed a tractable brain-body mechanism linking psychological states to host defense.