To investigate whether dietary patterns (Mediterranean diet [MedDiet], Dietary Approaches to Stop Hypertension [DASH], and A Priori Diet Quality Score [APDQS]) during adulthood are associated with midlife cognitive performance. We studied 2,621 Coronary Artery Risk Development in Young Adults (CARDIA) participants; 45% were black, 57% were female, and mean age was 25 ± 3.5 years at baseline (year 0). Mean diet scores were calculated from diet history at baseline, year 7, and year 20 (mean age 25, 32, and 45 years, respectively). Cognitive function was assessed at years 25 and 30 (mean age 50 and 55 years, respectively). Linear models were used to examine association between tertiles of diet score and change in composite cognitive function and cognitive z scores (verbal memory [Rey Auditory Verbal Learning Test], processing speed [Digit Symbol Substitution Test], and executive function [Stroop Interference test]) and the Montreal Cognitive Assessment (MoCA) at year 30. DASH was not associated with change in cognitive performance. Higher MedDiet and APDQS scores were associated with less decline in cognitive function (MedDiet: low -0.04, middle 0.03, high 0.03, p = 0.03; APDQS: low -0.04, middle -0.00, high 0.06, p < 0.01) and Stroop Interference (MedDiet: low 0.09, middle -0.06, high -0.03; APDQS: low 0.10, middle 0.01, high -0.09, both p < 0.01). Odds ratios (95% confidence interval) for poor global cognitive function (≥1 SD below mean MoCA score) comparing extreme tertiles of diet scores were 0.54 (0.39-0.74) for MedDiet, 0.48 (0.33-0.69) for APDQS, and 0.89 (0.68-1.17) for DASH. Greater adherence to MedDiet and APDQS dietary patterns during adulthood was associated with better midlife cognitive performance. Additional studies are needed to define the combination of foods and nutrients for optimal brain health across the life course.