Abstract Background: The discovery that ranitidine is contaminated with N-nitrosodimethylamine, a suspected human carcinogen, raises the hypothesis of a gastrointestinal carcinogenic effect; however, evidence remains inconclusive. Methods: We used the nationwide Danish Prescription Registry to identify a cohort of incident ranitidine users and two active comparator cohorts comprising users of other histamine-2 receptor blockers (H2RB) and users of proton pump inhibitors (PPI). All Danish adults with a first prescription of ranitidine, other H2RBs, or PPIs in 1996 through 2008 were followed virtually completely through 2018 for incidence of esophageal, stomach, liver, and pancreatic cancers. We used Cox regression with propensity-score weighting to calculate hazard ratios and 10-year cumulative risk with 95% confidence intervals. Results: We ascertained 276 newly diagnosed esophageal, 342 stomach, 133 hepatocellular, and 517 pancreatic cancers among ranitidine users during follow-up (median 14 years). In comparison with use of other H2RBs or PPIs, we found no consistent evidence of increased HRs or excess 10-year cumulative risk of any upper gastrointestinal cancer following ranitidine use. We observed no association after restriction to subjects with at least 5 or 10 prescriptions or those with 10 prescriptions and at least 10 years of follow-up. Conclusions: Our large prospective study using high-quality prescription and cancer incidence data, with two active comparator groups, provides no compelling evidence that ranitidine increases the risk of upper gastrointestinal cancers. Impact: Our results, which do not support any carcinogenic effect on esophagus, stomach, liver or pancreas, should be reassuring for millions of concerned past users of ranitidine.