Human studies on the use of metformin as host-directed therapy (HDT) for tuberculosis (TB) are rare. We performed a nationwide cohort study to evaluate the effect of metformin on mitigating the risk of active TB among patients with diabetes mellitus (DM). Among newly diagnosed DM patients identified in the Taiwan National Health Insurance Research Database, metformin users, defined on the basis of >90 cumulative defined daily doses within 1 year, and propensity-score-matched metformin nonusers were selected. The primary outcome was incident TB, identified using diagnostic criteria validated by real patient data at a medical center. Independent predictors were investigated using Cox regression analysis. Similar analysis was performed in a subpopulation without a history of hypertensive nephropathy and renal replacement therapy. A total of 88,866 metformin users and 88,866 propensity-score-matched nonusers were selected. Validation results showed that the TB diagnostic criteria had a sensitivity of 99.13% and specificity of 99.90%. During follow-up, 707 metformin users and 807 nonusers developed active TB. Metformin use was independently associated with a lower risk of incident TB (hazard ratio [HR]: 0.84 [0.74–0.96]). TB risk was lower in high-dose metformin users than in low-dose users (HR: 0.83 [0.72–0.97]). The effect of metformin remained when analysis was restricted in the subpopulation without renal function impairment. Newly diagnosed diabetic patients without contraindication should receive metformin as an anti-diabetic medication, with potential additional benefit against TB.