What makes diversity unifying in some settings but divisive in others? We examine how the mixing of ethnic groups in German schools affects intergroup cooperation and trust. We leverage the quasi-random assignment of students to classrooms within schools to obtain variation in the type of diversity that prevails in a peer group. We combine this with a large-scale, incentivized lab-in-field-experiment based on the investment game, allowing us to assess the in-group bias of native German students in their interactions with fellow natives (in-group) versus immigrants (out-group). We find in-group bias peaks in culturally polarized classrooms, where the native and immigrant groups are both large, but have different religious or language backgrounds. In contrast, in classrooms characterized by non cultural polarization, fractionalization, or a native supermajority, there are significantly lower levels of own-group favouritism. In terms of mechanisms, we find empirical evidence that culturally polarized classrooms foster negative stereotypes about immigrants’ trustworthiness and amplify taste-based discrimination, both of which are costly and lead to lower payouts. In contrast, accurate statistical discrimination is ruled out by design in our experiment. These findings suggest that extra efforts are needed to counteract low levels of inclusivity and trust in culturally polarized environments.