The mass-radius relation of white dwarfs is largely determined by the equation of state of degenerate electrons, which causes the stellar radius to decrease as mass increases. Here we observationally measure this relation using the gravitational redshift effect, a prediction of general relativity that depends on the ratio between stellar mass and radius. Using observations of over three thousand white dwarfs from the Sloan Digital Sky Survey and the Gaia space observatory, we derive apparent radial velocities from absorption lines, stellar radii from photometry and parallaxes, and surface gravities by fitting atmospheric models to spectra. By averaging the apparent radial velocities of white dwarfs with similar radii and, independently, surface gravities, we cancel out random Doppler shifts and measure the underlying gravitational redshift. Using these results, we empirically measure the white dwarf mass-radius relation across a wide range of stellar masses. Our results are consistent with leading theoretical models, and our methods could be used with future observations to empirically constrain white dwarf core composition and evolution.