Interleukin (IL)-22 is central to immune defense at barrier sites. We examined the contributions of innate lymphoid cell (ILC) and T cell-derived IL-22 during Citrobacter rodentium (C.r) infection using mice that both report Il22 expression and allow lineage-specific deletion. ILC-derived IL-22 activated STAT3 in C.r-colonized surface intestinal epithelial cells (IECs) but only temporally restrained bacterial growth. T cell-derived IL-22 induced a more robust and extensive activation of STAT3 in IECs, including IECs lining colonic crypts, and T cell-specific deficiency of IL-22 led to pathogen invasion of the crypts and increased mortality. This reflected a requirement for T cell-derived IL-22 for the expression of a host-protective transcriptomic program that included AMPs, neutrophil-recruiting chemokines, and mucin-related molecules, and it restricted IFNγ-induced proinflammatory genes. Our findings demonstrate spatiotemporal differences in the production and action of IL-22 by ILCs and T cells during infection and reveal an indispensable role for IL-22-producing T cells in the protection of the intestinal crypts.