Groundwater chemistry has been observed to change before earthquakes and is proposed as a precursor signal. Such changes include variations in radon count rates, concentrations of dissolved elements and stable isotope ratios. Changes in seismic wave velocities, water levels in boreholes, micro-seismicity and shear wave splitting are also thought to precede earthquakes. Precursor activity has been attributed to expansion of rock volume. However, most studies of precursory phenomena lack sufficient data to rule out other explanations unrelated to earthquakes. 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.