The final fate of massive stars, and the nature of the compact remnants they leave behind (black holes and neutron stars), are open questions in astrophysics. Many massive stars are stripped of their outer hydrogen envelopes as they evolve. Such Wolf–Rayet stars1 emit strong and rapidly expanding winds with speeds greater than 1,000 kilometres per second. A fraction of this population is also helium-depleted, with spectra dominated by highly ionized emission lines of carbon and oxygen (types WC/WO). Evidence indicates that the most commonly observed supernova explosions that lack hydrogen and helium (types Ib/Ic) cannot result from massive WC/WO stars2,3, leading some to suggest that most such stars collapse directly into black holes without a visible supernova explosion4. Here we report observations of SN 2019hgp, beginning about a day after the explosion. Its short rise time and rapid decline place it among an emerging population of rapidly evolving transients5–8. Spectroscopy reveals a rich set of emission lines indicating that the explosion occurred within a nebula composed of carbon, oxygen and neon. Narrow absorption features show that this material is expanding at high velocities (greater than 1,500 kilometres per second), requiring a compact progenitor. Our observations are consistent with an explosion of a massive WC/WO star, and suggest that massive Wolf–Rayet stars may be the progenitors of some rapidly evolving transients.