All societies need to form institutional rules to regulate their social interactions. These specify what actions individuals should take in particular situations, and what sanctions will apply if individuals violate these rules. However, forming these institutional rules involves playing a political game—a process of negotiation between individuals that is costly and time-consuming. Intuitively, this cost should be expected to increase as a group becomes larger, which could then select for a transition to hierarchy to keep the cost of playing the political game down as group size increases. However, previous work has lacked a mechanistic yet general model of political games that could formalize this argument and test the conditions under which it holds. We address this by formalizing the political game using a standard consensus formation model. We show that the increasing cost of forming a consensus over institutional rules selects for a transition from egalitarian to hierarchical organization over a wide range of conditions. Playing a political game to form institutional rules in this way captures and unites a previously disparate set of voluntary theories for hierarchy formation, and can explain why the increasing group size in the Neolithic would lead to strong political inequality.This article is part of the theme issue ‘Evolutionary ecology of inequality’.