We study the effects of voluntary participation on cooperation in collective action problems. Voluntary participation may foster cooperation through an entry mechanism, which leads to assortative selection of interaction partners, or an exit mechanism, whereby the opportunity to leave the partnership can be used as a threat against free-riders. We examine the effectiveness of these mechanisms in a one-shot public goods experiment. Voluntary participation has a positive effect on provision only through the exit mechanism. Assortative selection of interaction partners seems to play a minor role in our setting, whereas the threat of costly exit is a powerful force to discipline free-riding.