Plants synthesize a broad array of specialized chemical compounds that mediate their interactions with the surrounding environment. Some of this chemical diversity is functional and subject to natural selection, but the factors underlying chemical evolution at the intraspecific level remain largely unknown. Here, we combined chemical, environmental and genetic data to investigate the effect of aridity on the expression of chemotypes in the invasive shrub Senecio pterophorus. We studied the variation in pyrrolizidine alkaloids (PAs), a group of specialized metabolites widespread across the families Boraginaceae, Asteraceae and Fabaceae, from native populations spanning a cline of aridity and from three cross-continental introductions, under natural and common garden conditions. We examined whether the relationship between chemistry and aridity was compatible with a process of adaptive differentiation using a method that partitions the variance and covariance by controlling for the population neutral genetic structure. We found a consistent shift from retrorsine-like to seneciphylline-like compounds under increasing aridity in both natural and controlled conditions in coherence with the biosynthetic pathways. This pattern was independent of the neutral genetic structure and occurred along the environmental gradient in the native range and in a convergent manner in all nonnative regions, which suggests adaptive differentiation in response to aridity. Our findings show that the diversity of PAs in S. pterophorus has been partially shaped by aridity. Investigating how abiotic factors influence chemical evolution is key to elucidating the plant responses in future climate scenarios and the cascading effects on other trophic levels.