Public goods are the key features of all human societies and are also important in many animal societies. Collaborative hunting and collective defence are but two examples of public goods that have played a crucial role in the development of human societies and still play an important role in many animal societies. Public goods allow societies composed largely of cooperators to outperform societies composed mainly of non-cooperators. However, public goods also provide an incentive for individuals to be selfish by benefiting from the public good without contributing to it. This is the essential paradox of cooperation—known variously as the Tragedy of the Commons, Multi-person Prisoner's Dilemma or Social Dilemma. Here, we show that a new model for evolution in group-structured populations provides a simple and effective mechanism for the emergence and maintenance of cooperation in such a social dilemma. This model does not depend on kin selection, direct or indirect reciprocity, punishment, optional participation or trait-group selection. Since this mechanism depends only on population dynamics and requires no cognitive abilities on the part of the agents concerned, it potentially applies to organisms at all levels of complexity.