The light emitted by stars and accreting compact objects through the history of the universe is encoded in the intensity of the extragalactic background light (EBL). Knowledge of the EBL is important to understand the nature of star formation and galaxy evolution, but direct measurements of the EBL are limited by galactic and other foreground emissions. Here, we report an absorption feature seen in the combined spectra of a sample of gamma-ray blazars out to a redshift of z similar to 1.6. This feature is caused by attenuation of gamma rays by the EBL at optical to ultraviolet frequencies and allowed us to measure the EBL flux density in this frequency band.