Background & Aims: Helicobacter pylori (H pylori) is a risk factor for gastric cancer. We investigated whether early H pylori eradication is associated with gastric cancer risk in patients with peptic ulcer diseases. Methods: This nationwide cohort study was based on the Taiwan National Health Insurance Database (NHID), which provided data on 80,255 patients who were hospitalized for the first time between 1997 and 2004 with a primary diagnosis of peptic ulcer diseases and received H pylori eradication therapy. The patient population was divided into early (within 1 year) and late (after 1 year) eradication cohorts; standardized incidence ratios (SIRs) and hazards ratios (HRs) were determined. Results: There was no significant difference in gastric cancer risk between patients who received early H pylori eradication and the general population (SIR, 1.05; 95% confidence interval [CI]: 0.96-1.14), but late eradication was associated with an increased risk (SIR, 1.36; 95% CI: 1.24-1.49). In gastric ulcer patients who received early eradication, SIRs of gastric cancer decreased from 1.60 at 3-4 years to 1.05 at 7-10 years after hospitalization; the SIRs decreased from 0.57 to 0.33 for duodenal ulcer patients over the same period. Among patients who received late eradication, SIRs decreased from 2.14 to 1.32 for those with gastric ulcers and from 0.90 to 0.66 for those with duodenal ulcers. Early H pylori eradication (HR, 0.77) and frequent aspirin or nonsteroidal anti-inflammatory drug use (HR, 0.65) were independent protective factors for gastric cancer. Conclusions: Early H pylori eradication is associated with decreased risk of gastric cancer in patients with peptic ulcer diseases.