The Messinian salinity crisis-the desiccation of the Mediterranean Sea between 5.96 and 5.33 million years (Myr) ago-was one of the most dramatic events on Earth during the Cenozoic era. It resulted from the closure of marine gateways between the Atlantic Ocean and the Mediterranean Sea, the causes of which remain enigmatic. Here we use the age and composition of volcanic rocks to reconstruct the geodynamic evolution of the westernmost Mediterranean from the Middle Miocene epoch to the Pleistocene epoch (about 12.1-0.65Myr ago). Our data show that a marked shift in the geochemistry of mantle-derived volcanic rocks, reflecting a change from subduction-related to intraplate-type volcanism, occurred between 6.3 and 4.8Myr ago, largely synchronous with the Messinian salinity crisis. Using a thermomechanical model, we show that westward roll back of subducted Tethys oceanic lithosphere and associated asthenospheric upwelling provides a plausible mechanism for producing the shift in magma chemistry and the necessary uplift (~1km) along the African and Iberian continental margins to close the Miocene marine gateways, thereby causing the Messinian salinity crisis.