  Context. Diffusive shock acceleration (DSA) is the most promising mechanism
to accelerate Galactic cosmic rays (CRs) in the shocks of supernova remnants
(SNRs). The turbulence upstream is supposedly generated by the CRs, but this
process is not well understood. The dominant mechanism may depend on the
evolutionary state of the shock and can be studied via the CRs escaping
upstream into the interstellar medium (ISM). Aims. Previous observations of the
$\gamma$-Cygni SNR showed a difference in morphology between GeV and TeV
energies. Since this SNR has the right age and is at the evolutionary stage for
a significant fraction of CRs to escape, we aim to understand $\gamma$-ray
emission in the vicinity of the $\gamma$-Cygni SNR. Methods. We observed the
region of the $\gamma$-Cygni SNR with the MAGIC Imaging Atmospheric Cherenkov
telescopes between May 2015 and September 2017 recording 87 h of good-quality
data. Additionally we analysed Fermi-LAT data to study the energy dependence of
the morphology as well as the energy spectrum in the GeV to TeV range. The
energy spectra and morphology were compared against theoretical predictions,
which include a detailed derivation of the CR escape process and their
$\gamma$-ray generation. Results. The MAGIC and Fermi-LAT data allowed us to
identify three emission regions, which can be associated with the SNR and
dominate at different energies. Our hadronic emission model accounts well for
the morphology and energy spectrum of all source components. It constrains the
time-dependence of the maximum energy of the CRs at the shock, the
time-dependence of the level of turbulence, and the diffusion coefficient
immediately outside the SNR shock. While in agreement with the standard picture
of DSA, the time-dependence of the maximum energy was found to be steeper than
predicted and the level of turbulence was found to change over the lifetime of
the SNR.
