Cooperative behaviour is abundant in animal and human societies (

Binmore 1994;

Colman 1995;

Dugatkin 1997;

Doebeli & Hauert 2005). Well-known examples include vampire bats regurgitating blood to feed hungry conspecifics (

Wilkinson 1984), sticklebacks inspecting predatory pikes preferably in pairs (

Milinski 1987), alarm calls from watchful sentinels warning other meerkats from predators (

Clutton-Brock *et al*. 1999), musk oxen defending their young against wolves in groups (

Wilkinson & Shank 1977), etc. In all these examples, cooperative individuals provide a benefit to one or more individuals at some cost to themselves. However, this behaviour is prone to exploitation by defectors that readily accept support but avoid the costs of assisting others. In the complex society of humans, social interactions lead to multifaceted dilemmas of cooperation. This is most apparent in the consumption of various kinds of public resources, which include public transportation, social welfare, drinking water or clean air. All such resources are prone to exploitation and overuse, as exemplified by the metaphor of the

*The tragedy of the commons* (

Hardin 1968). Over the past decades, a number of mechanisms have been suggested which are capable of supporting cooperation in absence of genetic relatedness. Most notably, this includes repeated interactions and direct reciprocity (

Trivers 1971;

Axelrod & Hamilton 1981), punishment (

Clutton-Brock & Parker 1995;

Fehr & Gächter 2002), spatially structured populations (

Nowak & May 1992;

Hauert & Doebeli 2004) or voluntary participation in social interactions (

Hauert *et al*. 2002*b*). Unique to humans is apparently the capacity for indirect reciprocity (

Alexander 1987;

Nowak & Sigmund 1998,

2005) and the internalization of benefits as a foundation for moral systems.

Traditionally, the problem of cooperation in social dilemmas (

Dawes 1980;

Hauert *et al*. 2006) is investigated by means of the game theoretical models of the Prisoner's Dilemma for pairwise interactions and, more generally, public goods games for groups of interacting individuals (

Kagel & Roth 1995). In a typical public goods experiment, an experimenter endows, for example, four players with 10 dollars each. All players then have the opportunity to invest their money into a common pool knowing that the experimenter will double the total amount and divide it equally among all participants, irrespective of whether they contributed. Thus, if everybody invests their money, each player ends up with 20 dollars, i.e. doubles the invested money. However, every player faces the temptation to defect, because each invested dollar returns only 50 cents to the investor. Consequently, the rational, selfish solution is to withhold the money and attempt to free ride on the other players' contributions—but if everybody follows this reasoning, no one increases the initial capital and foregoes the benefits of the public good.

In formal terms, the payoffs for cooperators and defectors in a group with

*k* cooperators is given by

where

*r* denotes the multiplication factor,

*c* the cooperative investment and

*N* the size of the group engaging in public goods interactions. For simplicity, the costs

*c* are set to unity in the remainder of the text. Note that for pairwise interactions (

*N*=2), the public goods formalism can be easily mapped onto the traditional formulation of the Prisoner's Dilemma in terms of costs that a cooperator incurs and benefits that accrue exclusively to their interaction partners (

Hauert & Szabó 2003).

In populations of interacting individuals, the dynamics of cooperators and defectors in the public goods game is determined by their respective payoffs obtained in randomly formed groups of

*N* individuals. Thus, any given focal individual finds itself in a group with

other individuals. If

*x* is the frequency of cooperators in the population, then the chance that

*k* of those other individuals are cooperators is

This probability is independent of whether the focal individual is a cooperator or a defector. Therefore, every focal individual encounters the same expected number of cooperators, and hence the same expected payoff from the other players during game interactions. From this it follows that the only determinant of success in the well-mixed public goods game is the payoff that the focal individual receives from itself. This payoff is zero if the focal individual is a defector, and is equal to

if the focal individual is a cooperator. The traditional formulation of public goods games requires

, such that defectors are better off and

*x*=0 is globally stable. Conversely, for

*r*>

*N*, the social dilemma posed by the public goods game is relaxed and cooperation dominates. However, also note that even in this case, defectors are better off than cooperators in any group consisting of both types. The fact that evolution nevertheless favours cooperation represents an instance of Simpson's paradox (

Simpson 1951;

Hauert *et al*. 2002*b*). This follows by noting that in this case cooperators receive, on average, higher payoffs than defectors according to the argument given above.

The basic idea of the present paper is that if the public goods game is played in populations of varying densities, then the effective group size

*S* of the public goods interactions also varies. Small population densities result in small effective group sizes and vice versa if population densities are large. Assuming that birth rates are proportional to payoffs, population growth is small or negative if defectors abound, because payoffs in groups with many defectors are low according to equations

(1.1*a*) and

(1.1*b*). However, if population densities decrease, then the effective interaction group size

*S* also decreases until eventually

*r*>

*S* holds and cooperation is favoured. Thus, we expect scenarios where large population densities favour defection, leading to a decrease in population density and hence to a decrease in

*S*, which, in turn, favours cooperation. Here, we show that this feedback between game dynamics and ecological dynamics can maintain cooperation and lead to stable coexistence of cooperators and defectors.