BackgroundEmpirical evidence indicates that both HIV infection and stunting impede cognitive functions of school-going children. However, there is less evidence on how these two risk factors amplify each other’s negative effects. This study aimed to examine the direct effects of stunting on cognitive outcomes and the extent to which stunting (partially) mediates the effects of HIV, age, and gender on cognitive outcomes.MethodologyWe applied structural equation modelling to cross-sectional data from 328 children living with HIV and 260 children living without HIV aged 6–14 years from Nairobi, Kenya to test the mediating effect of stunting and predictive effects of HIV, age, and gender on cognitive latent variables flexibility, fluency, reasoning, and verbal memory.ResultsThe model predicting the cognitive outcomes fitted well (RMSEA = 0.041, CFI = 0.966, χ2= 154.29, DF = 77,p< 0.001). Height-for-age (a continuous indicator of stunting) predicted fluency (β= 0.14) and reasoning (β= 0.16). HIV predicted height-for-age (β= −0.24) and showed direct effects on reasoning (β= −0.66), fluency (β= −0.34), flexibility (β= 0.26), and verbal memory (β= −0.22), highlighting that the effect of HIV on cognitive variables was partly mediated by height-for-age.ConclusionIn this study, we found evidence that stunting partly explains the effects of HIV on cognitive outcomes. The model suggests there is urgency to develop targeted preventative and rehabilitative nutritional interventions for school children with HIV as part of a comprehensive set of interventions to improve cognitive functioning in this high-risk group of children. Being infected or having been born to a mother who is HIV positive poses a risk to normal child development.