Carbon, nitrogen and oxygen are the three most abundant elements in the Galaxy after hydrogen and helium. Whereas hydrogen and helium were created in the Big Bang, carbon, nitrogen and oxygen arise from nucleosynthesis in stars. Of particular interest1,2 are the isotopic ratios 12C/13C, 14N/15N and 16O/17O because they are effective tracers of nucleosynthesis and help to benchmark the chemical processes that occurred in primitive interstellar material as it evolved into our Solar System3. However, the origins of the rare isotopes 15N and 17O remain uncertain, although novae and very massive stars that explode as supernovae are postulated4,5,6 to be the main sources of 15N. Here we report millimetre-wavelength observations of the young bipolar planetary nebula K4-47 that indicate another possible source for these isotopes. We identify various carbon-bearing molecules in K4-47 that show that this object is carbon-rich, and find unusually high enrichment in rare carbon (13C), oxygen (17O) and nitrogen (15N) isotopes: 12C/13C = 2.2 ± 0.8, 16O/17O = 21.4 ± 10.3 and 14N/15N = 13.6 ± 6.5 (uncertainties are three standard deviations); for comparison, the corresponding solar ratios7 are 89.4 ± 0.2, 2,632 ± 7 and 435 ± 57. One possible interpretation of these results is that K4-47 arose from a J-type asymptotic giant branch star that underwent a helium-shell flash (an explosive nucleosynthetic event that converts large quantities of helium to carbon and other elements), enriching the resulting planetary nebula in 15N and 17O and creating its bipolar geometry. Other possible explanations are that K4-47 is a binary system or that it resulted from a white dwarf merger, as has been suggested for object CK Vul8. These results suggest that nucleosynthesis of carbon, nitrogen and oxygen is not well understood and that the classification of certain stardust grains must be reconsidered.