Explaining altruistic cooperation is one of the greatest challenges for evolutionary biology1,2,3. One solution to this problem is if costly cooperative behaviours are directed towards relatives4,5. This idea of kin selection has been hugely influential and applied widely from microorganisms to vertebrates2,3,4,5,6,7,8,9,10. However, a problem arises if there is local competition for resources, because this leads to competition between relatives, reducing selection for cooperation3,11,12,13,14. Here we use an experimental evolution approach to test the effect of the scale of competition, and how it interacts with relatedness. The cooperative trait that we examine is the production of siderophores, iron-scavenging agents, in the pathogenic bacterium Pseudomonas aeruginosa15,16,17. As expected, our results show that higher levels of cooperative siderophore production evolve in the higher relatedness treatments. However, our results also show that more local competition selects for lower levels of siderophore production and that there is a significant interaction between relatedness and the scale of competition, with relatedness having less effect when the scale of competition is more local. More generally, the scale of competition is likely to be of particular importance for the evolution of cooperation in microorganisms, and also the virulence of pathogenic microorganisms, because cooperative traits such as siderophore production have an important role in determining virulence6,9,17,18,19.