Today, boys generally underperform relative to girls in schools throughout the industrialized world. Building on theories about gender identity and reports from prior ethnographic classroom observations, we argue that school environment channels conceptions of masculinity in peer culture, fostering or inhibiting boys’ development of anti-school attitudes and behavior. Girls’ peer groups, by contrast, vary less strongly with the social environment in the extent to which school engagement is stigmatized as un-feminine. As a consequence, boys are more sensitive than girls to school resources that create a learning-oriented environment. To evaluate this argument, we use a quasi-experimental research design and estimate the gender difference in the causal effect of peer socioeconomic status (SES) as an important school resource on test scores. Our design is based on the assumption that assignment to 5th-grade classrooms within Berlin’s schools is as good as random, and we evaluate this selection process with an examination of Berlin’s school regulations, a simulation analysis, and qualitative interviews with school principals. Estimates of the effect of SES composition on male and female performance strongly support our central hypothesis, and other analyses support our proposed mechanism as the likely explanation for gender differences in the causal effect.