The study included 875 patients with cancer of the upper gastrointestinal tract (esophagus, stomach, duodenum) diagnosed between 2003–2024 and 8750 controls matched for age, sex, ethnicity, socioeconomic status, and year of enrollment. At diagnosis, the use of proton pump inhibitors (PPIs) was associated with an increased likelihood of cancer, e.g. esomeprazole aOR 4.01 (95% CI 3.20–5.03, p < 0.001) and omeprazole aOR 2.38 (95% CI 1.99–2.80, p < 0.001). After excluding the last year before diagnosis and adjusting for upper GI symptoms, no adverse association was demonstrated. Long-term use of PPIs (> 3 years before diagnosis) was, on the other hand, associated with a reduced probability of cancer, e.g. omeprazole aOR 0.62 (95% CI 0.51–0.75, p < 0.001). Similar findings were true for the gastric cancer subgroup (701 cases, 7010 controls). Apparent risks were concentrated in the months before diagnosis because of reverse causality and confounding by indication. Limitations include possible residual confounding, missing data on diet, family history, and over-the-counter PPIs.