Classical novae are runaway thermonuclear burning events on the surfaces of accreting white dwarfs in close binary star systems, sometimes appearing as new naked-eye sources in the night sky. The standard model of novae predicts that their optical luminosity derives from energy released near the hot white dwarf which is reprocessed through the ejected material. Recent studies with the Fermi Large Area Telescope have shown that many classical novae are accompanied by gigaelectronvolt gamma-ray emission. This emission likely originates from strong shocks, providing new insights into the properties of nova outflows and allowing them to be used as laboratories to study the unknown efficiency of particle acceleration in shocks. Here we report gamma-ray and optical observations of the Milky Way nova ASASSN-16ma, which is among the brightest novae ever detected in gamma-rays. The gamma-ray and optical light curves show a remarkable correlation, implying that the majority of the optical light comes from reprocessed emission from shocks rather than the white dwarf. The ratio of gamma-ray to optical flux in ASASSN-16ma directly constrains the acceleration efficiency of non-thermal particles to be ~0.005, favouring hadronic models for the gamma-ray emission. The need to accelerate particles up to energies exceeding 100 gigaelectronvolts provides compelling evidence for magnetic field amplification in the shocks.