Previous observational studies have reported a relationship between negative emotions and upper gastrointestinal disease. However, whether this relationship is causal remains unclear. We aimed to evaluate the causal relationship between negative emotions and upper gastrointestinal diseases using two-sample Mendelian randomization (MR). Three sets of genetic instruments from the database were obtained for analysis, including 12 anxiety-related single nucleotide polymorphisms (SNPs), 46 depression-related SNPs, and 58 nervous-related SNPs. SNPs were filtered using the Phenoscanner website, and the inverse variance weighted method, weighted median method, MR-Egger regression, MR pleiotropy residual sum, and outlier test were used for analysis. In inverse variance weighted analysis, anxiety and depression had an effect on gastroduodenal ulcer (p = 2.849 × 10-3, β = 4.908, 95% CI = 1.684–8.132; and p = 6.457 × 10-4, β = 1.767, 95% CI = 0.752–2.782, respectively). Additionally, depression had an effect on diseases of the esophagus, stomach, and duodenum (p = 3.498 × 10-5,β = 0.926,95% CI = 0.487–1.364). Cochran’s Q-derived p-values were 0.457, 0.603, and 0.643, and MR-Egger intercept-derived p-values were 0.697, 0.294, and 0.362, respectively. Here, we show that anxiety and depression have a causal relationship with gastroduodenal ulcers, and depression has a causal relationship with diseases of the esophagus, stomach, and duodenum.