Ethnic diversity has been linked to important social outcomes such as economic underperformance and civil war, yet its study is still hampered by conceptual difficulties and imprecise measurement. In this paper, a modified understanding of ethnic diversity is developed. Ethnic diversity is disaggregated into two components—first- and second-order ethnic diversity—which have opposing consequences for collective outcomes. While first-order ethnic diversity—the diversity of a local community—is theorized to undermine cooperation, second-order ethnic diversity—the ethnic diversity of the hinterland of a community—is theorized to induce ethnic competition, thereby reinforcing cooperation. Relating data from over 100,000 individuals interviewed at 2,942 locations in 33 African countries to novel sub-national indicators of first- and second-order ethno-linguistic diversity, the theory is tested and its basic tenets confirmed. In a next step, I show that it is indeed ethnic competition that accounts for the positive association between second-order diversity and increased cooperation: second-order ethnic diversity is a much better predictor of cooperation in regions where contemporary or historical factors have exacerbated interethnic tensions. The paper sheds new light on the debate on the consequences of ethnic diversity for cooperation and contributes to our understanding of the origins of the global ‘geography of social capital’.