Why do communities with larger shares of ethnic and racial minorities have worse public outcomes such as service provision? Many studies emphasize the role of diversity and other demographic variables, but the question of causality remains underexplored. We contribute to this debate by tracing the roots of contemporary racial demography and public goods provision to the uneven historical expansion of the state in Brazil. We show more remote municipalities with lower levels of state capacity in the past were more frequently selected by escaped slaves to serve as permanent settlements. Consequently, such municipalities have worse public services and larger shares of Afro-descendants today. These results indicate pervasive endogeneity of ethnic demography and public outcomes, which are both influenced by state development. Failure to account for this and other context-dependent historical confounders raises concerns over the validity of previous findings regarding the social costs and benefits of any particular demographic composition.