This paper investigates how high school gender composition affects students' participation in STEM college studies. Using Danish administrative data, we exploit idiosyncratic within-school variation in gender composition. We find that having a larger proportion of female peers reduces women's probability of enrolling in and graduating from STEM programs. Men's STEM participation increases with more female peers present. In the long run, women exposed to more female peers earn less because they (1) are less likely to work in STEM occupations, and (2) have more children. Our findings show that the school peer environment has lasting effects on occupational sorting and the gender wage gap.