Host immunity and commensal bacteria synergistically maintain intestinal homeostasis and mediate colonization resistance against pathogens. However, the molecular and cellular mechanisms remain unclear. Here, with a mouse infection model of Citrobacter rodentium, a natural mouse intestinal pathogen that mimics human enteropathogenic Escherichia coli and enterohaemorrhagic Escherichia coli, we find that group 3 innate lymphoid cells (ILC3s) can protect the host from infection by regulating gut microbiota. Mechanistically, ILC3s can control gut dysbiosis through IL-22-dependent regulation of intestinal galactosylation in mice. ILC3 deficiency led to an increase in intestinal galactosylation and the expansion of commensal Akkermansia muciniphila in colonic mucus. The increased A. muciniphila and A. muciniphila-derived metabolic product succinate further promoted the expression of pathogen virulence factors tir and ler, resulting in increased susceptibility to C. rodentium infection. Together, our data reveal a mechanism for ILC3s in protecting against pathogen infection through the regulation of intestinal glycosylation and gut microbiota metabolism.