As the prevalence of childhood mental health conditions varies by age and gender, we explored whether there were similar variations in the relationship between psychopathology and exclusion from school in a prospective UK population-based birth cohort. The Avon Longitudinal Study of Parents and Children collected reports of exclusion at 8 years and 16 years. Mental health was assessed at repeated time points using the Strengths and Difficulties Questionnaire (SDQ). Using adjusted linear mixed effects models, we detected a nonlinear interaction between exclusion and age related to poor mental health for boys [adjusted coefficient 1.13 (95% confidence interval 0.55-1.71)] excluded by age 8, but not for girls. The SDQ scores of boys who were excluded in primary school were higher than their peers from age 3, and increasingly diverged over time. As teenagers, these interactions appeared for both genders [boys' adjusted coefficient 0.18 (0.10-0.27); girls 0.29 (0.17-0.40)]. For teenage girls, exclusion by 16 was followed by deteriorating mental health. Family adversity predicted exclusion in all analyses. Prompt access to effective intervention for children in poor mental health may improve both mental health and access to education. Children who were subsequently excluded from school often faced family adversity and had poor mental health, which suggests the need for an interdisciplinary response and a multiagency approach. Poor mental health may contribute to and result from exclusion from school, so both mental health and education practitioners have a key role to play. Boys who enter school with poor mental health are at high risk of exclusion in primary school, which prompt assessment and intervention may prevent. Both boys and girls who are excluded between the ages of 15 and 16 years may have poor, and in the case of girls, deteriorating, mental health. © 2020 The Authors. Child and Adolescent Mental Health published by John Wiley & Sons Ltd on behalf of Association for Child and Adolescent Mental Health.