Background: Patients with cancer are at high risk for having mental disorders, resulting in widespread psychosocial screening efforts. However, there is a need for population-based and longitudinal studies of mental disorders among patients who have gastrointestinal cancer and particular among elderly patients. Patients and Methods: We used the SEER-Medicare database to identify patients aged ≥65 years with colorectal, pancreatic, gastric, hepatic/biliary, esophageal, or anal cancer. Earlier (12 months before or up to 6 months after cancer diagnosis) and subsequent mental disorder diagnoses were identified. Results: Of 112,283 patients, prevalence of an earlier mental disorder was 21%, 23%, 20%, 20%, 19%, and 26% for colorectal, pancreatic, gastric, hepatic/biliary, esophageal, and anal cancer, respectively. An increased odds of an earlier mental disorder was associated with pancreatic cancer (odds ratio [OR], 1.17; 95% CI, 1.11–1.23), esophageal cancer (OR, 1.10; 95% CI, 1.02–1.18), and anal cancer (OR, 1.17; 95% CI, 1.05–1.30) compared with colorectal cancer and with having regional versus local disease (OR, 1.09; 95% CI, 1.06–1.13). The cumulative incidence of a subsequent mental disorder at 5 years was 19%, 16%, 14%, 13%, 12%, and 10% for patients with anal, colorectal, esophageal, gastric, hepatic/biliary, and pancreatic cancer, respectively. There was an association with having regional disease (hazard ratio [HR], 1.08; 95% CI, 1.04–1.12) or distant disease (HR, 1.36; 95% CI, 1.28–1.45) compared with local disease and the development of a mental disorder. Although the development of a subsequent mental disorder was more common among patients with advanced cancers, there continued to be a significant number of patients with earlier-stage disease at risk. Conclusions: This study suggests a larger role for incorporating psychiatric symptom screening and management throughout oncologic care.