Background: The relationship between immune cells and colorectal cancer (CRC) development has been extensively studied; however, the mediating role of gut microbiota in this relationship remains poorly understood. Methods: We utilized summary data from genome-wide association studies (GWAS) to analyze 731 immune cell phenotypes, 473 gut microbiota, and CRC-related data. A two-step mediation analysis was employed to identify mediating gut microbiota. The primary analysis method was inverse variance weighting (IVW), supplemented by MR-Egger, simple mode, weighted median, and weighted mode analyses. Robustness of the results was ensured through systematic sensitivity analyses. Results: Our analysis identified 13 immune cell phenotypes significantly associated with CRC, including 10 protective factors and 3 risk factors. Additionally, 13 gut microbiota showed significant associations with CRC, comprising 8 protective factors and 5 risk factors. Mediation analysis revealed that 4-gut microbiota (1 order, 1 family, 1 genus, and 1 unclassified) mediated the relationship between immune cells and CRC. For instance, unclassified CAG − 977 mediated the effects of FSC-A on NK and NKT %lymphocyte on CRC risk, with mediation proportions of 11% and 12.3%, respectively. Notably, 22.3% of the protective effect of EM CD8br %CD8br on CRC was mediated through order Francisellales. Conclusion: This study provides evidence for a potential causal relationship between immune cells, gut microbiota, and CRC, highlighting the mediating role of specific gut microbiota. These findings offer new insights into the pathogenesis of CRC and may inform future therapeutic strategies. © The Author(s) 2025.