Dietary patterns in childhood have been associated with child neurodevelopment and cognitive performance, while the underlying neurobiological pathway is unclear. We aimed to examine associations of dietary patterns in infancy and mid-childhood with pre-adolescent brain morphology, and whether diet-related differences in brain morphology mediate the relation with cognition. We included 1888 and 2326 children with dietary data at age one or eight years, respectively, and structural neuroimaging at age 10 years in the Generation R Study. Measures of brain morphology were obtained using magnetic resonance imaging. Dietary intake was assessed using food-frequency questionnaires, from which we derived diet quality scores based on dietary guidelines and dietary patterns using principal component analyses. Full scale IQ was estimated using the Wechsler Intelligence Scale for Children-Fifth Edition at age 13 years. Children with higher adherence to a dietary pattern labeled as ‘Snack, processed foods and sugar’ at age one year had smaller cerebral white matter volume at age 10 (B = -4.3, 95%CI -6.9, -1.7). At age eight years, higher adherence to a ‘Whole grains, soft fats and dairy’ pattern was associated with a larger total brain (B = 8.9, 95%CI 4.5, 13.3), and larger cerebral gray matter volumes at age 10 (B = 5.2, 95%CI 2.9, 7.5). Children with higher diet quality and better adherence to a ‘Whole grains, soft fats and dairy’ dietary pattern at age eight showed greater brain gyrification and larger surface area, clustered primarily in the dorsolateral prefrontal cortex. These observed differences in brain morphology mediated associations between dietary patterns and IQ. In conclusion, dietary patterns in early- and mid-childhood are associated with differences in brain morphology which may explain the relation between dietary patterns and neurodevelopment in children.Supplementary InformationThe online version contains supplementary material available at 10.1007/s10654-023-01012-5.