INTRODUCTION: Metformin has been suggested as a therapeutic agent for dementia, but the relevant evidence has been partial and inconsistent. METHODS: We established a national cohort of 210,237 type 2 diabetes patients in the UK Clinical Practice Research Datalink. Risks of incident dementia were compared between metformin initiators and those who were not prescribed any anti-diabetes medication during follow-up. RESULTS: Compared with metformin initiators (n = 114,628), patients who received no anti-diabetes medication (n = 95,609) had lower HbA1c and better cardiovascular health at baseline. Both Cox regression and propensity score weighting analysis showed metformin initiators had lower risk of dementia compared to those non-users (adjusted hazard ratio = 0.88 [95% confidence interval: 0.84-0.92] and 0.90 [0.84-0.96]). Patients on long-term metformin treatment had an even lower risk of dementia. DISCUSSION: Metformin may act beyond its glycemic effect and reduce dementia risk to an even lower level than that of patients with milder diabetes and better health profiles. HIGHLIGHTS: Metformin initiators had a significantly lower risk of dementia compared with patients not receiving anti-diabetes medication. Compared with metformin initiators, diabetes patients not receiving pharmacological treatment had better glycemic profiles at baseline and during follow-up. Patients on long-term metformin treatment had an even lower risk of subsequent dementia incidence. Metformin may act beyond its effect on hyperglycemia and has the potential of being repurposed for dementia prevention.