  In recent years, millisecond duration radio signals originating from distant
galaxies appear to have been discovered in the so-called Fast Radio Bursts.
These signals are dispersed according to a precise physical law and this
dispersion is a key observable quantity which, in tandem with a redshift
measurement, can be used for fundamental physical investigations. While every
fast radio burst has a dispersion measurement, none before now have had a
redshift measurement, due to the difficulty in pinpointing their celestial
coordinates. Here we present the discovery of a fast radio burst and the
identification of a fading radio transient lasting $\sim 6$ days after the
event, which we use to identify the host galaxy; we measure the galaxy's
redshift to be $z=0.492\pm0.008$. The dispersion measure and redshift, in
combination, provide a direct measurement of the cosmic density of ionised
baryons in the intergalactic medium of $\Omega_{\mathrm{IGM}}=4.9 \pm 1.3\%$,
in agreement with the expectation from WMAP, and including all of the so-called
"missing baryons". The $\sim6$-day transient is largely consistent with a short
gamma-ray burst radio afterglow, and its existence and timescale do not support
progenitor models such as giant pulses from pulsars, and supernovae. This
contrasts with the interpretation of another recently discovered fast radio
burst, suggesting there are at least two classes of bursts.
