Groundwater chemistry has been observed to change before earthquakes and is proposed as a precursor signal. Such changes include variations in radon count rates1, 2, concentrations of dissolved elements3, 4, 5 and stable isotope ratios4, 5. Changes in seismic wave velocities6, water levels in boreholes7, micro-seismicity8 and shear wave splitting9 are also thought to precede earthquakes. Precursor activity has been attributed to expansion of rock volume7, 10, 11. However, most studies of precursory phenomena lack sufficient data to rule out other explanations unrelated to earthquakes12. For example, reproducibility of a precursor signal has seldom been shown and few precursors have been evaluated statistically. Here we analyse the stable isotope ratios and dissolved element concentrations of groundwater taken from a borehole in northern Iceland between 2008 and 2013. We find that the chemistry of the groundwater changed four to six months before two greater than magnitude 5 earthquakes that occurred in October 2012 and April 2013. Statistical analyses indicate that the changes in groundwater chemistry were associated with the earthquakes. We suggest that the changes were caused by crustal dilation associated with stress build-up before each earthquake, which caused different groundwater components to mix. Although the changes we detect are specific for the site in Iceland, we infer that similar processes may be active elsewhere, and that groundwater chemistry is a promising target for future studies on the predictability of earthquakes.