The organosulfur compound dimethylsulfoniopropionate (DMSP) has key roles in stress protection, global carbon and sulfur cycling, chemotaxis, and is a major source of climate-active gases. Saltmarshes are global hotspots for DMSP cycling due to Spartina cordgrasses that produce exceptionally high concentrations of DMSP. Here, in Spartina anglica, we identify the plant genes that underpin high-level DMSP synthesis: methionine S-methyltransferase (MMT), S-methylmethionine decarboxylase (SDC) and DMSP-amine oxidase (DOX). Homologs of these enzymes are common in plants, but differences in expression and catalytic efficiency explain why S. anglica accumulates such high DMSP concentrations and other plants only accumulate low concentrations. Furthermore, DMSP accumulation in S. anglica is consistent with DMSP having a role in oxidative and osmotic stress protection. Importantly, administration of DMSP by root uptake or over-expression of Spartina DMSP synthesis genes confers plant tolerance to salinity and drought offering a route for future bioengineering for sustainable crop production.