Background: Although prior studies showed metformin could reduce gastric cancer (GC) risk in patients with diabetes mellitus (DM), they failed to adjust for Helicobacter pylori infection and glycemic control. We aimed to investigate whether metformin reduced GC risk in H. pylori-eradicated diabetic patients and its association with glycemic control. Methods: This was a territory-wide cohort study using hospital registry database, recruiting all diabetic patients who were prescribed clarithromycin-based triple therapy for H. pylori infection from 2003 to 2012. Subjects were observed from H. pylori therapy prescription until GC diagnosis, death or end of study (December 2015). Exclusion criteria included GC diagnosed within first year of H. pylori therapy, prior history of GC or gastrectomy, and failure of H. pylori eradication. The hazard ratio (HR) of GC with metformin (defined as at least 180-day use) was estimated by Cox model with propensity score adjustment for covariates (age, sex, comorbidities, medications [including insulin], and time-weighted average hemoglobin A1c [HbA1c]). All statistical tests were two-sided. Results: During a median follow-up of 7.1 years (IQR:4.7-9.8), 37 (0.51%) of 7,266 diabetic patients developed GC at a median age of 76.4 years (IQR: 64.8-81.5 years). Metformin use was associated with a reduced GC risk (adjusted HR:0.49; 95% CI:0.24-0.98). There was a trend towards a lower GC risk with increasing duration (ptrend =0.01) and dose of metformin (ptrend=0.02). HbA1c level was not an independent risk factor for GC.