The W51 complex hosts the supernova remnant W51C which is known to interact with the molecular clouds in the star forming region W51B. In addition, a possible pulsar wind nebula CXO J192318.5+140305 was found likely associated with the supernova remnant. Gamma-ray emission from this region was discovered by Fermi/LAT (between 0.2 and 50 GeV) and H.E.S.S. (>1 TeV). The spatial distribution of the events could not be used to pinpoint the location of the emission among the pulsar wind nebula, the supernova remnant shell and/or the molecular cloud. However, the modeling of the spectral energy distribution presented by the Fermi/LAT collaboration suggests a hadronic emission mechanism. We performed observations of the W51 complex with the MAGIC telescopes for more than 50 hours. The good angular resolution in the medium (few hundred GeV) to high (above 1 TeV) energies allow us to perform morphological studies. We detect an extended emission of very-high-energy gamma rays, with a significance of 11 standard deviations. We extend the spectrum from the highest Fermi/LAT energies to sim 5 TeV and find that it follows a single power law with an index of 2.58 pm 0.07stat pm 0.22syst . The main part of the emission coincides with the shocked cloud region, while we find a feature extending towards the pulsar wind nebula. The possible contribution of the pulsar wind nebula, assuming a point-like source, shows no dependence on energy and it is about 20% of the overall emission. The broad band spectral energy distribution can be explained with a hadronic model that implies proton acceleration above 100 TeV. This result, together with the morphology of the source, tentatively suggests that we observe ongoing acceleration of ions in the interaction zone between supernova remnant and cloud. These results shed light on the long-standing problem of the origin of galactic cosmic rays.