Measurement of the extragalactic background light using MAGIC and Fermi-LAT gamma-ray observations of blazars up to z = 1