In protection mutualisms, one mutualist defends its partner against a natural enemy in exchange for a reward, usually food or shelter. For both partners, the costs and benefits of these interactions often vary considerably in space because the outcome (positive, negative or neutral) depends on the local abundance of at least three species: the protector, the beneficiary of protection and the beneficiary's natural enemy. In Gossypium thurberi (wild cotton), ants benefit nutritionally from the plant's extrafloral nectaries and guard plants from herbivores. Experimentally altering the availability of both ants and extrafloral nectar in three populations demonstrated that the mutualism is facultative, depending, in part, on the abundance of ants and the level of herbivore damage. The species composition of ants and a parasitic alga that clogs extrafloral nectaries were also implicated in altering the outcome of plant-ant interactions. Furthermore, experimental treatments that excluded ants (the putative selective agents) in combination with phenotypic selection analyses revealed that selection on extrafloral nectary traits was mediated by ants and, importantly, varied across populations. This work is some of the first to manipulate interactions experimentally across multiple sites and thereby document that geographically variable selection, mediated by a mutualist, can shape the evolution of plant traits.