Abstract Objective The present study aims to investigate the protective role of metformin against atrial fibrillation (AF) and stroke in type 2 diabetes (T2DM) patients treated with other antidiabetic medications. Methods We included 10,011 participants with T2DM from the UK biobank database, with a follow-up for new diagnoses of AF and stroke recorded until 2023. We employed logistic regression analysis and competing risk models to assess the association between metformin use and the incidence of AF or stroke. Results The cross-sectional analysis revealed that, compared with the use of other antidiabetics, metformin was associated with a lower prevalence of AF (odds ratio [OR] 0.71, 95% CI: 0.57–0.89) and stroke (OR 0.70, 95% CI: 0.56–0.86). In the competing risk model, compared to other antidiabetics, metformin may reduce the risk of AF (sub-hazard ratio [SHR] 0.86, 95% CI: 0.75–0.98) and stroke (SHR 0.62, 95% CI: 0.44–0.86) (Figure 1). Subgroup analysis indicated a significantly lower incidence of AF or stroke in patients under 65 years of age (SHRs were 0.80, 95% CI:0.67-0.96 for AF and 0.52, 95% CI: 0.34-0.81 for stroke) and in female patients (SHRs were 0.65, 95% CI:0.52-0.81 for AF and 0.53, 95% CI: 0.30-0.91 for stroke). Notably, metformin significantly reduced the incidence of AF in non-insulin users (SHR 0.80, 95% CI: 0.66-0.97) and the incidence of stroke in insulin users (SHR 0.55, 95% CI: 0.35-0.87) (Figure 2). Conclusion Our findings suggest that metformin use, in comparison to other antidiabetic medications, is associated with a reduced risk of AF and stroke, especially in non-insulin users for AF and insulin users for stroke.