Objective: To compare the risks of gastric cancer and other gastric diseases upon exposed to sodium-glucose cotransporter 2 inhibitors (SGLT2I), dipeptidyl peptidase-4 inhibitors (DPP4I) and glucagon-like peptide-1 receptor agonists (GLP1A). Design: This was a retrospective population-based cohort study of prospectively recorded data on type-2 diabetes mellitus (T2DM) patients prescribed either SGLT2I or DPP4I between January 1st 2015 and December 31st 2020 from Hong Kong. The primary outcome was new-onset gastric cancer, peptic ulcer (PU), acute gastritis, non-acute gastritis, and gastroesophageal reflux disease (GERD). Propensity score matching (1:1 ratio) using the nearest neighbour search was performed and multivariable Cox regression was carried out. A three-arm analysis including the GLP1A cohort was subsequently conducted. Results: A total of 62858 T2DM patients (median age: 62.2 years old [SD: 12.8]; 55.93% males; SGLT2I: n=23442; DPP4I: n=39416) were included. After matching, the incidence of gastric cancer was significantly lower in SGLT2I users (Incidence rate, IR: 0.32; 95% confidence interval, CI: 0.23-0.43) than DPP4I users (IR: 1.22; CI: 1.03-1.42). SGLT2I use was associated with lower risks of gastric cancer (HR: 0.30; 95% CI: 0.19-0.48) after adjusting for significant covariates compared to DPP4I use. SGLT2 use was also associated with lower risks of PU, acute gastritis, non-acute gastritis, and GERD (all p<0.05). The three-arm analysis demonstrated higher risks of gastric cancer and GERD in GLP1A than in SGLT2I. Conclusions: SGLT2I was associated with lower risks of new-onset gastric cancer, PU, acute gastritis, non-acute gastritis, and GERD after matching and adjustments compared to DPP4I.