Functions of the human gut virome are little understood, particularly for the hyperabundant prophages integrated in prokaryotic genomes. Here we identified 254,273 prophage sequences in 47.7% of 289,232 human gut metagenomic genomes, significantly expanding the known taxonomic and functional diversity of prophages in the human gut microbiome. Analysis of 8503 gut metagenomic samples showed the ratios of lysogens (cells harboring prophages) to non-lysogens varied widely associated with age, health condition, and geography, with the latter linked to industrialization. Notably, the alterations of the prophage-encoded genes exhibited disease-specific patterns. For inflammatory bowel diseases, the prophage-encoded futC gene, encoding α-1,2-fucosyltransferase, was less prevalent in affected patients. This enzyme was experimentally validated to direct 2-fucosyllactose (2'-FL) biosynthesis in vitro. Here we show that 2'-FL could diminish colitis in mice induced by treatment with dextran sodium sulfate. Mechanistically, 2'-FL promoted maintenance of mucosal barrier integrity, leading to intestinal IgA secretion and intraepithelial CD4⁺CD8αα⁺ T cell development mediated by the gut microbiome. Together, our findings thus link lysogeny to human age, geography, and disease, and demonstrate an immunomodulatory mechanism of prophage-encoded genes in alleviating colitis.