The historic detection of gravitational waves from a binary neutron star merger (GW170817) and its electromagnetic counterpart led to the first accurate (sub-arcsecond) localization of a gravitational-wave event. The transient was found to be $sim$10 from the nucleus of the S0 galaxy NGC 4993. We report here the luminosity distance to this galaxy using two independent methods. (1) Based on our MUSE/VLT measurement of the heliocentric redshift ($z_{rm helio}=0.009783pm0.000023$) we infer the systemic recession velocity of the NGC 4993 group of galaxies in the cosmic microwave background (CMB) frame to be $v_{rm CMB}=3231 pm 53$ km s$^{-1}$. Using constrained cosmological simulations we estimate the line-of-sight peculiar velocity to be $v_{rm pec}=307 pm 230$ km s$^{-1}$, resulting in a cosmic velocity of $v_{rm cosmic}=2924 pm 236$ km s$^{-1}$ ($z_{rm cosmic}=0.00980pm 0.00079$) and a distance of $D_z=40.4pm 3.4$ Mpc assuming a local Hubble constant of $H_0=73.24pm 1.74$ km s$^{-1}$ Mpc$^{-1}$. (2) Using Hubble Space Telescope measurements of the effective radius (15.5 $pm$ 1.5) and contained intensity and MUSE/VLT measurements of the velocity dispersion, we place NGC 4993 on the Fundamental Plane (FP) of E and S0 galaxies. Comparing to a frame of 10 clusters containing 226 galaxies, this yields a distance estimate of $D_{rm FP}=44.0pm 7.5$ Mpc. The combined redshift and FP distance is $D_{rm NGC 4993}= 41.0pm 3.1$ Mpc. This electromagnetic distance estimate is consistent with the independent measurement of the distance to GW170817 as obtained from the gravitational-wave signal ($D_{rm GW}= 43.8^{+2.9}_{-6.9}$ Mpc) and confirms that GW170817 occurred in NGC 4993.