  Context. QSO B0218+357 is a gravitationally lensed blazar located at a
redshift of 0.944. The gravitational lensing splits the emitted radiation into
two components, spatially indistinguishable by gamma-ray instruments, but
separated by a 10-12 day delay. In July 2014, QSO B0218+357 experienced a
violent flare observed by the Fermi-LAT and followed by the MAGIC telescopes.
Aims. The spectral energy distribution of QSO B0218+357 can give information on
the energetics of z ~ 1 very high energy gamma- ray sources. Moreover the
gamma-ray emission can also be used as a probe of the extragalactic background
light at z ~ 1. Methods. MAGIC performed observations of QSO B0218+357 during
the expected arrival time of the delayed component of the emission. The MAGIC
and Fermi-LAT observations were accompanied by quasi-simultaneous optical data
from the KVA telescope and X-ray observations by Swift-XRT. We construct a
multiwavelength spectral energy distribution of QSO B0218+357 and use it to
model the source. The GeV and sub-TeV data, obtained by Fermi-LAT and MAGIC,
are used to set constraints on the extragalactic background light. Results.
Very high energy gamma-ray emission was detected from the direction of QSO
B0218+357 by the MAGIC telescopes during the expected time of arrival of the
trailing component of the flare, making it the farthest very high energy
gamma-ray sources detected to date. The observed emission spans the energy
range from 65 to 175 GeV. The combined MAGIC and Fermi-LAT spectral energy
distribution of QSO B0218+357 is consistent with current extragalactic
background light models. The broad band emission can be modeled in the
framework of a two zone external Compton scenario, where the GeV emission comes
from an emission region in the jet, located outside the broad line region.
