The optimal defence hypothesis predicts that plant parts characterized by a high value and/or a high risk of being attacked should exhibit the highest level of defence. We tested this hypothesis with Macaranga bancana ant-plants, which are protected efficiently by resident, mutualistic ants from herbivores, parasites and encroaching vegetation. Because cost-effective defence of the host by ants increases ant fitness, selection should act on ant behaviour to produce patterns of distribution of defence as predicted for direct chemical defence traits. Termites and pieces of tape were equally distributed over the uppermost ten leaves and over the leaf-bearing part of the stems (with termites mimicking a transient herbivore, while tape mimics a long-term stress caused by a climber or plant parasite). This arrangement allowed a separation of putative coevolutionary adaptations in the ants' behaviour from other potential sources of spatial patterns in ant defence, such as differences in herbivore pressure, in the vulnerability of different herbivores, or in direct plant defences. Ant activity dropped rapidly at termite baits, but remained high at tapes for at least 5 h, thereby demonstrating adaptive differential responses to the differences between the two stressors. Most importantly, ants preferentially defended young leaves and shoot parts. The temporal and spatial patterns of ant attention to exogenous stressors thus were clearly adaptive, varying with likely costs and benefits of defence as formulated in the optimal defence theory.