Close friendships are important for mental health and cognition in late childhood. However, whether the more close friends the better, and the underlying neurobiological mechanisms are unknown. Using the Adolescent Brain Cognitive Developmental study, we identified nonlinear associations between the number of close friends, mental health, cognition, and brain structure. Although few close friends were associated with poor mental health, low cognitive functions, and small areas of the social brain (e.g., the orbitofrontal cortex, the anterior cingulate cortex, the anterior insula, and the temporoparietal junction), increasing the number of close friends beyond a level (around 5) was no longer associated with better mental health and larger cortical areas, and was even related to lower cognition. In children having no more than five close friends, the cortical areas related to the number of close friends revealed correlations with the density of μ-opioid receptors and the expression of OPRM1 and OPRK1 genes, and could partly mediate the association between the number of close friends, attention-deficit/hyperactivity disorder (ADHD) symptoms, and crystalized intelligence. Longitudinal analyses showed that both too few and too many close friends at baseline were associated with more ADHD symptoms and lower crystalized intelligence 2 y later. Additionally, we found that friendship network size was nonlinearly associated with well-being and academic performance in an independent social network dataset of middle-school students. These findings challenge the traditional idea of ‘the more, the better,’ and provide insights into potential brain and molecular mechanisms.