Background: Previous studies have suggested that gut microbiota and immune system regulation have potential links with type 2 diabetes (T2D). However, the causal association between gut microbiota and T2D and whether immune cells mediate this interaction is unclear. Methods: A two-sample, two-step Mendelian randomization (MR) study utilizing an initial inverse-variance weighted (IVW) method was performed to explore the causal impact of gut microbiota on T2D and the intermediary role of immune cells. Results: The MR analysis assigned 4 gut microbiota and metabolic pathways that increase the risk of T2D (G_Prevotella, g_Anaerotruncus, g_Streptococcus.s_ Streptococcus_parasanguinis, and the pathway of PANTO-PWY) and 4 other gut microbiota and metabolic pathways that have a protective effect against T2D (PWY5667, PWY-6892, PWY-7221, and the bacterial g_Paraprevotella.s_Paraprevotella_ clara). Furthermore, 17 immune cell traits have been identified as associated with T2D. The finding from mediation MR analysis revealed that PANTO-PWY increases T2D risk via CD3 on HLA DR+ CD4+, whereas PWY-7221 reduces T2D risk through CD4 on CD4 Treg. Conclusion: The research reveals a mediated causal link between the gut microbiota and T2D via immune cells.