The light emitted by all galaxies over the history of the Universe produces the extragalactic background light (EBL) at ultraviolet, optical, and infrared wavelengths. The EBL is a source of opacity for gamma rays via photon-photon interactions, leaving an imprint in the spectra of distant gamma-ray sources. We measured this attenuation using 739 active galaxies and one gamma-ray burst detected by the Fermi Large Area Telescope. This allowed us to reconstruct the evolution of the EBL and determine the star formation history of the Universe over 90% of cosmic time. Our star formation history is consistent with independent measurements from galaxy surveys, peaking at redshift z ~ 2. Upper limits of the EBL at the epoch of reionization suggest a turnover in the abundance of faint galaxies at z ~ 6.