Diet could affect risk for esophageal and gastric cancers, but associations have been inconsistent. The diet is complex, so studies of dietary patterns, rather than studies of individual foods, might be more likely to identify cancer risk factors. There is limited research on index-based dietary patterns and esophageal and gastric cancers. We prospectively evaluated associations between the Healthy Eating Index-2005 (HEI-2005) and alternate Mediterranean Diet (aMED) scores and risk of esophageal and gastric cancers. We analyzed data from 494,968 participants in the National Institutes of Health-AARP Diet and Health study, in which AARP members (age, 51-70 y) completed a self-administered baseline food frequency questionnaire between 1995 and 1996. Their answers were used to estimate scores for each index. During the follow-up period (1995-2006), participants developed 215 esophageal squamous cell carcinomas (ESCCs), 633 esophageal adenocarcinomas (EACs), 453 gastric cardia adenocarcinomas, and 501 gastric noncardia adenocarcinomas. Higher scores from the HEI-2005 were associated with a reduced risk of ESCC (comparing the highest quintile with the lowest quintile: hazard ratio, 0.51; 95% confidence interval, 0.31-0.86; Ptrend = .001) and EAC (hazard ratio, 0.75; 95% confidence interval, 0.57-0.98; Ptrend = .01). We observed an inverse association between ESCC, but not EAC, and a higher aMED score (meaning a higher-quality diet). HEI-2005 and aMED scores were not associated significantly with gastric cardia or noncardia adenocarcinomas. By using data collected from 1995 through 2006 from the National Institutes of Health-AARP Diet and Health Study, HEI-2005 and aMED scores were associated inversely with risk for esophageal cancers, particularly ESCC. Adherence to dietary recommendations might help prevent esophageal cancers. Published by Elsevier Inc.