Economic, social and political inequality between different identity groups is an important contributor to violent conflicts within societies. To deepen our understanding of the underlying social dynamics, we develop a mathematical model describing cooperation and conflict in a society composed of multiple factions engaged in economic and political interactions. Our model predicts that growing economic and political inequality tends to lead to the collapse of cooperation between factions that were initially seeking to cooperate. Certain mechanisms can delay this process, including the decoupling of political and economic power through rule of law and allegiance to the state or dominant faction. Counterintuitively, anti-conformity (a social norm for independent action) can also stabilize society, by preventing initial defections from cooperation from cascading through society. However, the availability of certain material resources that can be acquired by the state without cooperation with other factions has the opposite effect. We test several of these predictions using a multivariate statistical analysis of data covering 75 countries worldwide. Using social unrest as a proxy for the breakdown of cooperation in society, we find support for many of the predictions from our theory.