Conventional wisdom claims that racial diversity undermines public goods provision. I show that class-based differences, instead, incentivize cooperation for public goods. Class-based segregation reduces spatial externalities of inequality (e.g., sewage pollution and crime) spilling over from impoverished areas (e.g., slums) to the middle class. Conversely, I argue that in integrated (de-segregated) cities, the scale of such externalities undermines the efficacy of private services (e.g., private security), thereby inducing middle-class preferences for externalities-correcting public goods. Thus, while segregation polarizes preferences, integration aligns the middle class with the poor in coalitions that support public goods over private alternatives. I illustrate the theory using focus groups, a proposed quasi-experimental strategy, and an original face-to-face survey of 4,208 households across 420 neighborhoods in São Paulo, Brazil. The analysis introduces self-interest in reducing intergroup externalities as a mechanism for cooperation for public goods even in diverse societies. Using mechanism vignettes, I distinguish the mechanism from the affective attitudes—racial tolerance, social affinity—of intergroup contact.