As cooperation incurs a cost to the cooperator for others to benefit, its evolution seems to contradict natural selection. How evolution has resolved this obstacle, has been among the most intensely studied questions in the evolutionary theory in recent decades. Here, by showing that competition between public resources provides a simple mechanism for cooperation to flourish, we uncover a novel road to the evolution of cooperation. Such a mechanism can be at work in many biological or social contexts where individuals can form different groups or join different institutions to perform a collective action task, or when they can choose between different collective actions, with different profitability. As a simple evolutionary model suggests, in such a context, defectors tend to join the highest quality resource. This allows cooperators to survive and out-compete defectors by sheltering in a lower quality resource. Cooperation level is maximized however, when the qualities of the two highest quality resources are similar, and thus, they can perform the most competitively to attract individuals.