Background Helicobacter pylori infection is an important risk factor for gastric cancer. In Japan, national health insurance has covered eradication therapy for H. pylori infection-associated gastritis from 2013. However, gastric cancer was the fourth leading cause of cancer death in 2023. We aimed to investigate differences in gastric cancer risk among patients with gastritis, gastric ulcer, duodenal ulcer, and gastric ulcer and duodenal ulcer after H. pylori eradication. Methods This retrospective cohort study used the JMDC Claims Database from February 21, 2013, to August 31, 2023. Patients who received first-line H. pylori eradication therapy and were diagnosed with H. pylori-associated gastritis, gastric ulcer, or duodenal ulcer in the same month or the month before the first eradication therapy prescription were included. Two antibacterial drugs and an acid secretion inhibitor or triple-drug blister-packaged product were prescribed. The primary outcome was gastric cancer incidence. A Cox proportional hazards regression analysis was used to estimate hazard ratios (HRs). A propensity score approach was used to minimize the effect of confounding measures. Results Of 17,245,330 beneficiaries, 148,489 were included. In the weighted cohort (after propensity matching), statistically significant differences were observed in HRs between H. pylori-associated gastritis and duodenal ulcer (HR using the latter as a reference [95% confidence interval]: 2.03 [1.31-3.13]; p = 0.001), and between gastric ulcer and duodenal ulcer (2.37 [1.52-3.71]; p < 0.001). The cumulative probabilities (95% confidence interval) per the median follow-up years (3.8 years for all) were 0.44% (0.39-0.48) for H. pylori-associated gastritis, 0.54% (0.46-0.63) for gastric ulcer, 0.22% (0.10-0.33) for duodenal ulcer, and 0.26% (0.08-0.50) for gastric ulcer and duodenal ulcer. Conclusions Patients with H. pylori-associated gastritis and gastric ulcer had a higher risk of gastric cancer than patients with duodenal ulcer, indicating that gastric atrophy remains a risk factor after H. pylori eradication therapy. Careful monitoring, such as by endoscopic examination, is required after successful eradication of H. pylori in patients at higher risk.