Ulcerative colitis (UC) is a chronic and recurrent inflammatory disease with an unknown pathogenesis and increasing incidence. The objective of this study is to investigate the impact of prophylactic treatment with Cordyceps militaris on UC. The findings demonstrate that prophylactic supplementation of C. militaris powder effectively mitigates disease symptoms in DSS-injured mice, while also reducing the secretion of pro-inflammatory cytokines. Furthermore, C. militaris powder enhances the integrity of the intestinal mucosal barrier by up-regulating MUC2 protein expression and improving tight junction proteins (ZO-1, occludin, and claudin 1) in DSS-injured mice. Multiomics integration analyses revealed that C. militaris powder not only reshaped gut microbiota composition, with an increase in Lactobacillus, Odoribacter, and Mucispirillum, but also exerted regulatory effects on various metabolic pathways including amino acid, glyoxylates, dicarboxylates, glycerophospholipids, and arachidonic acid. Subsequent analysis further elucidated the intricate interplay of gut microbiota, the intestinal mucosal barrier, and metabolites, suggesting that the microbiota–metabolite axis may involve the effect of C. militaris on intestinal mucosal barrier repair in UC. Moreover, in vitro experiments demonstrated that peptides and polysaccharides, derived from C. militaris, exerted an ability to change the gut microbiota structure of UC patients’ feces, particularly by promoting the growth of Lactobacillus. These findings suggest that regulatory properties of C. militaris on gut microbiota may underlie the potential mechanism responsible for the protective effect of C. militaris in UC. Consequently, our study will provide support for the utilization of C. militaris as a whole food-based ingredient against the occurrence and development of UC.