This study evaluated whether metformin might reduce esophageal cancer risk. Patients with type 2 diabetes mellitus diagnosed during 1999-2005 were recruited from the reimbursement database of Taiwan's National Health Insurance. Those newly treated with metformin (n = 288013, "ever users of metformin") or other antidiabetic drugs (n = 16216, "never users of metformin") were followed until December 31, 2011. Sensitivity analyses were conducted in a matched-pair sample of 16216 never users and 16216 ever users. Hazard ratios were estimated by Cox regression incorporated with the inverse probability of treatment weighting using propensity score. The risk associated with infection of Helicobacter pylori, Epstein-Barr virus, hepatitis B virus and hepatitis C virus was also evaluated. Results showed that the incidence of esophageal cancer in ever and never users was 25.03 and 50.87 per 100,000 person-years, respectively. The overall hazard ratio (95% confidence intervals) of 0.487 (0.347-0.684) suggested a significantly lower risk among metformin users. Hazard ratios comparing the first (46.00 months) tertile of cumulative duration of metformin use to never users was 1.184 (0.834-1.680), 0.403 (0.276-0.588) and 0.113 (0.071-0.179), respectively. Infection of Helicobacter pylori (but not the other viral infections) significantly increased the risk, which could be ameliorated by metformin. Analyses in the matched sample consistently supported a protective role of metformin. In conclusion, metformin reduces esophageal cancer risk when the cumulative duration is more than approximately 2 years.