The evolutionary arms race between plants and herbivores has led to numerous plant adaptations, including spinescence. However, whether spinescence evolved primarily in response to herbivory, or whether abiotic conditions also played a role, remains unknown. We integrated phylogenetic, geographic, and trait data for 2,686 species of an ecologically diverse and spiny pantropical lineage, mimosoid legumes, with data for 235 extant and 185 extinct mammalian herbivores >10 kg. Using structural equation models, we assessed how herbivores, climate and fire directly and indirectly affected the proportion of spinescent mimosoids across global and continental assemblages. The proportion of spinescent mimosoids in assemblages increased with extant and extinct herbivore richness, drought and heat, while fire influenced spinescence indirectly, by affecting herbivore richness. Notably, correlations of spinescence differed between Africa and America, with increasing importance of extinct herbivores in Africa, illustrating legacy effects on spinescence. Megaherbivores have shaped spinescence in mimosoids, especially in dry environments, where losing plant tissues is costly. Spinescence originated ~35 Mya, with the transition of mimosoids to seasonally dry environments, pre-dating the Miocene expansion of savannas. Our study suggests that both long-term climatic transitions and the emergence of open, herbivore-rich landscapes played crucial roles in the evolution and distribution of spinescence.