Here, we show that ileal expression of AGR2 correlates with mucosal Enterobactericeae abundance in human inflammatory bowel disease (IBD) and that Agr2 deletion leads to ER-stress-dependent expansion of mucosal-associated adherent-invasive Escherichia coli (AIEC), which drives Th17 cell ileocolitis in mice. Here, AGR2 is linked to ileocolitis.