Abiotic environmental variables strongly affect the outcomes of species interactions. For example, mutualistic interactions between species are often stronger when resources are limited. The effect might be indirect: water stress on plants can lead to carbon stress, which could alter carbon-mediated plant mutualisms. In mutualistic ant–plant symbioses, plants host ant colonies that defend them against herbivores. Here we show that the partners' investments in a widespread ant–plant symbiosis increase with water stress across 26 sites along a Mesoamerican precipitation gradient. At lower precipitation levels, Cordia alliodora trees invest more carbon in Azteca ants via phloem-feeding scale insects that provide the ants with sugars, and the ants provide better defense of the carbon-producing leaves. Under water stress, the trees have smaller carbon pools. A model of the carbon trade-offs for the mutualistic partners shows that the observed strategies can arise from the carbon costs of rare but extreme events of herbivory in the rainy season. Thus, water limitation, together with the risk of herbivory, increases the strength of a carbon-based mutualism.