Metformin has been shown to possess immune-modulating and anti-inflammatory effects in various animal and clinical studies. It is believed to be effective in treating some immune-mediated inflammatory diseases (IMIDs). However, there remains ongoing debate regarding the extent to which metformin can reduce the risk of developing IMIDs. We used the data from genome-wide association studies to explore the causal relationship between metformin treatment and some IMIDs through the Mendelian randomization (MR) analysis. Additionally, sensitivity analyses were performed using the Cochran Q-test, MR-PRESSO and "leave-one-out" to confirm the robustness of our conclusions. The MR analysis indicated that metformin treatment could reduce the risk of rheumatoid arthritis (RA) (OR = 0.018, 95% CI: 1.33 × 10-3-0.233, P = .002), multiple sclerosis (MS) (OR = 0.966, 95% CI: 0.936-0.997, P = .030) and primary sclerosing cholangitis (PSC) (OR = 6.82 × 10-4, 95% CI: 7.83 × 10-6-5.93 × 10-2, P = .001). But metformin treatment is not significantly associated with the risk of Crohn disease (OR = 0.994, 95% CI: 0.979-1.009, P = .431), ulcerative colitis (UC) (OR = 0.987, 95% CI: 0.965-1.009, P = .234), systemic lupus erythematosus (SLE) (OR = 164.373, 95% CI: 0.158-1.71 × 105, P = .150), autoimmune hepatitis (AIH) (OR = 2.909, 95% CI: 4.58 × 10-3-1.85 × 103, P = .746) and primary biliary cholangitis (PBC) (OR = 0.055, 95% CI: 1.44 × 10-3-2.112, P = .119). Due to the heterogeneity of the data from UC, SLE, MS, and PBC, we adjusted them. After adjustment, there is no change in the results for UC, SLE, MS, and PBC. The findings of this study support metformin treatment may reduce the risk of RA, MS, and PSC.