The evolution of cooperation among nonrelated individuals is one of the fundamental problems in biology and social sciences. Reciprocal altruism fails to provide a solution if interactions are not repeated often enough or groups are too large. Punishment and reward can be very effective but require that defectors can be traced and identified. Here we present a simple but effective mechanism operating under full anonymity. Optional participation can foil exploiters and overcome the social dilemma. In voluntary public goods interactions, cooperators and defectors will coexist. We show that this result holds under very diverse assumptions on population structure and adaptation mechanisms, leading usually not to an equilibrium but to an unending cycle of adjustments (a Red Queen type of evolution). Thus, voluntary participation offers an escape hatch out of some social traps. Cooperation can subsist in sizable groups even if interactions are not repeated, defectors remain anonymous, players have no memory, and assortment is purely random.