Cross-sectional study aimed to analyse differences in cognitive performance across fitness components categories (cardiorespiratory fitness [CRF], speed-agility and muscular fitness [MF]) and weight status in children, and to determine whether physical fitness mediates the association between body mass index (BMI) and cognitive performance. Fitness components and BMI were measured using standard procedures in 630 children aged 5-to-7 years from the provinces of Cuenca and Ciudad Real, Spain. BADyG was used to assess cognitive performance. We used ANCOVA models to test mean differences in cognition scores by BMI and fitness categories. Hayes's PROCESS macro was used for mediation analyses. Children with normal weight scored better in spatial factor and general intelligence than their overweight/obese peers (p < 0.05), but differences were attenuated when controlling for CRF (p > 0.05). Children with better results in CRF and speed-agility scored better in all cognitive dimensions even after controlling for BMI (p < 0.05). Similarly, children with high MF obtained better scores in verbal factor (p < 0.05). All fitness components acted as mediators of the relationship between BMI and general intelligence (p < 0.05). These findings highlight the crucial role of fitness in minimising the negative effect of excess weight on children's cognition. Abbreviations: BMI: Body mass index; CRF: Cardiorespiratory fitness; MF: Muscular fitness; BADyG E1: Battery of general and differential aptitudes; SES: Socioeconomic status; SD: Standard deviation; IE: Indirect effect.