Helicobacter pylori infection, now considered to be a cause of gastric cancer, is also strongly associated with gastric and duodenal ulcer disease. The discovery of these relations has brought the long-controversial connection between peptic ulcers and gastric cancer into focus. We estimated the risk of stomach cancer in a large cohort of hospitalized patients with gastric or duodenal ulcers, as recorded in the Swedish Inpatient Register between 1965 and 1983. Altogether, 57,936 patients were followed through 1989, for an average of 9.1 years. The standardized incidence ratio--the ratio of the observed number of cancers to the number expected on the basis of the incidence in the Swedish population at large--was used as a measure of relative risk. After peaking in the first 3 years of follow-up, the standardized incidence ratio for gastric cancer among 29,287 patients with gastric ulcers leveled off at 1.8 (95 percent confidence interval, 1.6 to 2.0) and remained significantly increased throughout follow-up, which was as long as 24 years for some patients. Prepyloric ulcer, diagnosed in 8646 patients, was not associated with a significant excess risk (standardized incidence ratio, 1.2; 95 percent confidence interval, 0.8 to 1.6). In the cohort of patients with duodenal ulcers (24,456 patients), the incidence of gastric cancer was significantly lower than expected. After the second year of follow-up, the standardized incidence ratio was only 0.6 (95 percent confidence interval, 0.4 to 0.7) and remained stable thereafter. Gastric ulcer disease and gastric cancer have etiologic factors in common. A likely cause of both is atrophic gastritis induced by H. pylori. By contrast, there appear to be factors associated with duodenal ulcer disease that protect against gastric cancer.