Classical novae are thermonuclear explosions that occur on the surfaces of white dwarf stars in interacting binary systems1. It has long been thought that the luminosity of classical novae is powered by continued nuclear burning on the surface of the white dwarf after the initial runaway2. However, recent observations of gigaelectronvolt γ-rays from classical novae have hinted that shocks internal to the nova ejecta may dominate the nova emission. Shocks have also been suggested to power the luminosity of events as diverse as stellar mergers3, supernovae4 and tidal disruption events5, but observational confirmation has been lacking. Here we report simultaneous space-based optical and γ-ray observations of the 2018 nova V906 Carinae (ASASSN-18fv), revealing a remarkable series of distinct correlated flares in both bands. The optical and γ-ray flares occur simultaneously, implying a common origin in shocks. During the flares, the nova luminosity doubles, implying that the bulk of the luminosity is shock powered. Furthermore, we detect concurrent but weak X-ray emission from deeply embedded shocks, confirming that the shock power does not appear in the X-ray band and supporting its emergence at longer wavelengths. Our data, spanning the spectrum from radio to γ-ray, provide direct evidence that shocks can power substantial luminosity in classical novae and other optical transients.