Prior research has found that boys often outperform girls in high-stakes math exams, affecting access to selective university programs and later careers. Using administrative and survey data linked to a lottery-based school assignment system, we show that this gender gap is substantially reduced in single-sex schools. Girls randomly assigned to single-sex schools exert more effort, narrow the math performance gap with boys in high-stakes exams, and are more likely to enroll in STEM degrees excluding biology. These gains come at a cost to well-being, reflected in higher stress and worse mental health. The effects are not explained by teacher gender, school resources, or differential selection into science tracks. Our findings are consistent with theories emphasizing the social costs of norm violation: single-sex schools may reduce peer pressures that discourage academic ambition in competitive and male-dominated domains.