BackgroundCross-sectional studies have suggested an association between the use of social media and depression and anxiety in young people. We examined the longitudinal relationship between social media use and young people's mental health, and the role of self-esteem and social connectedness as potential mediators. MethodsAdolescents (aged 10–15 years) from the UK Longitudinal Household Study (2009–19) were included. Mental health was measured by the Strengths and Difficulties Questionnaire Total Difficulties score. The number of hours spent on social media was measured on a 5-point scale, from zero to ≥7 h. Self-esteem and social connectedness were measured at ages 13–14 years. Covariates included demographic and household variables. Unadjusted and adjusted multilevel linear regression models explored whether social media use at ages 12–13 years predicted mental health at ages 14–15 years (expressed as beta values and 95% CIs). Path analysis with structural equation modelling was used to investigate the mediation pathways. FindingsWe included 3228 adolescents (1659 [51·4%] girls and 1569 [48·6%] boys) for whom social media and mental health data at ages 12–13 years and 14–15 years were available. In adjusted analysis, no association between time spent on social media and poorer mental health was identified (n=2603; b=0·21 [95% CI –0·43 to 0·84]; p=0·52). In adjusted path analysis, there was no mediation of self-esteem (indirect effect; n=2316; b=0·24 [95% CI –0·12 to 0·66]; p=0·22) or social connectedness (indirect effect; –0·03 [–0·20 to 0·12]; p=0·74), but in unadjusted analysis, 68% of the effect of social media use on mental health was mediated by self-esteem (indirect effect; n=2569; 0·70 [0·15 to 1·30]; p=0.016) but not by social connectedness. Similar results were found when the analysis was re-run on a multiply imputed dataset that filled in missing values using multiple imputation. InterpretationOur data show the importance of longitudinal evidence. We found there was little evidence to suggest a causal relationship between the use of social media and mental health issues 2 years later. Interventions that address social media use alone might not improve young people's mental health, and considering factors such as self-esteem might be more effective. FundingUK National Institute for Health Research School for Public Health Research (grant reference PD-SPH-2015). The views expressed are those of the authors and not necessarily those of the National Institute for Health Research or the UK Department of Health and Social Care.