Graphite vaporization provides an uncontrolled yet efficient means of producing fullerene molecules. However, some fullerene derivatives or unusual fullerene species might only be accessible through rational and controlled synthesis methods. Recently, such an approach has been used to produce isolable amounts of the fullerene C60 from commercially available starting materials. But the overall process required 11 steps to generate a suitable polycyclic aromatic precursor molecule, which was then dehydrogenated in the gas phase with a yield of only about one per cent. Here we report the formation of C60 and the triazafullerene C57N3 from aromatic precursors using a highly efficient surface-catalyzed cyclodehydrogenation process. We find that after deposition onto a platinum (111) surface and heating to 750 K, the precursors are transformed into the corresponding fullerene and triazafullerene molecules with about 100 per cent yield. We expect that this approach will allow the production of a range of other fullerenes and heterofullerenes, once suitable precursors are available. Also, if the process is carried out in an atmosphere containing guest species, it might even allow the encapsulation of atoms or small molecules to form endohedral fullerenes.