Shergottites, the most abundant martian meteorites, represent the best source of information about Mars’ mantle and its dissolved water. If the mantle was wet, magmatic degassing could have supplied substantial water to the martian surface early in its history. Researchers have attempted to reconstruct the volatile contents of shergottite parental magmas, with recent analyses confirming that the shergottites contained significant water. However, water is not a passive tracer; it directly affects magma chemistry and physical properties. Deciphering the history of water on Mars requires understanding how that water affected the chemistry of the shergottites and how they fit within Mars’ geologic history. Both topics present difficulties, as no shergottite-like rock has been found in stratigraphic context and there is debate over the timing of eruptions of shergottite-like magmas. Partial melting experiments on terrestrial basalts and new data from orbiters and rovers on Mars provide the information needed to overcome these difficulties and explain the role of water in shergottite magmas. Here we show that shergottite compositions and their martian geologic context can be explained by melting of an originally wet mantle that degassed over time. We also demonstrate that models for the evolution of the martian mantle that do not consider water fail to account for the shergottite compositions, surface distributions, and ages. Finally, we suggest that dehydration of the martian mantle has led to changes in magmatic chemistry over time, with shergottites representing melts of water-bearing mantle and rocks similar to nakhlites representing melts of other mantle sources.