Although Galactic cosmic rays (protons and nuclei) are widely believed to be mainly accelerated by the winds and supernovae of massive stars, definitive evidence of this origin remains elusive nearly a century after their discovery. The active regions of starburst galaxies have exceptionally high rates of star formation, and their large size—more than 50 times the diameter of similar Galactic regions—uniquely enables reliable calorimetric measurements of their potentially high cosmic-ray density. The cosmic rays produced in the formation, life and death of massive stars in these regions are expected to produce diffuse γ-ray emission through interactions with interstellar gas and radiation. M82, the prototype small starburst galaxy, is predicted to be the brightest starburst galaxy in terms of γ-ray emission. Here we report the detection of >700-GeV γ-rays from M82. From these data we determine a cosmic-ray density of 250 eV cm-3 in the starburst core, which is about 500 times the average Galactic density. This links cosmic-ray acceleration to star formation activity, and suggests that supernovae and massive-star winds are the dominant accelerators.