Classical novae are thermonuclear explosions that occur on the surfaces of white dwarf stars in interacting binary systems (Bode & Evans 2008). 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 runaway (Gallaher & Starrfield 1978). However, recent observations of GeV $gamma$-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 mergers (Metzger & Pejcha 2017), supernovae (Moriya et al. 2018), and tidal disruption events (Roth et al. 2016), but observational confirmation has been lacking. Here we report simultaneous space-based optical and $gamma$-ray observations of the 2018 nova V906 Carinae (ASASSN-18fv), revealing a remarkable series of distinct correlated flares in both bands. The optical and $gamma$-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 $gamma$-ray, provide direct evidence that shocks can power substantial luminosity in classical novae and other optical transients.