Background: Anxiety and depression are more common in children with obesity than in children of normal weight, but it is unclear whether this association is independent of other known risk factors. Interpretation of results from previous studies is hampered by methodological limitations, including self-reported assessment of anxiety, depression, and anthropometry. The aim of this study was to investigate whether obesity increases the risk of anxiety or depression independently of other risk factors in a large cohort of children and adolescents, using robust measures with regard to exposure and outcome. Methods: Children aged 6-17 years in the Swedish Childhood Obesity Treatment Register (BORIS, 2005-2015) were included (n = 12,507) and compared with a matched group (sex, year of birth, and area of residence) from the general population (n = 60,063). The main outcome was a diagnosis of anxiety or depression identified through ICD codes or dispensed prescribed medication within 3 years after the end of obesity treatment. Hazard ratios (HRs) with 95% confidence intervals (CIs) from Cox proportional models were adjusted for several known confounders. Results: Obesity remained a significant risk factor for anxiety and depression in children and adolescents after adjusting for Nordic background, neuropsychiatric disorders, family history of anxiety/depression, and socioeconomic status. Girls in the obesity cohort had a 43% higher risk of anxiety and depression compared to girls in the general population (adjusted HR 1.43, 95% CI 1.31-1.57; p < 0.0001). The risk in boys with obesity was similar (adjusted HR 1.33, 95% CI 1.20-1.48; p < 0.0001). In sensitivity analyses, excluding subjects with neuropsychiatric disorders and a family history of anxiety/depression, the estimated risks in individuals with obesity were even higher compared with results from the main analyses (adjusted HR [95% CI]: girls = 1.56 [1.31-1.87], boys = 2.04 [1.64-2.54]). Conclusions: Results from this study support the hypothesis that obesity per se is associated with risk of both anxiety and depression in children and adolescents.