One of the biggest challenges for materials science is to design facile routes to structurally complex materials, which is particularly important for global applications such as fuel cells. Doped nanostructured carbons are targeted as noble metal-free electrocatalysts for this purpose. Their intended widespread use, however, necessitates simple and robust preparation methods that do not compromise on material performance. Here, we demonstrate a versatile one-pot synthesis of nitrogen-doped carbons that exploits the templating ability of biological polymers. Starting with just metal nitrates and gelatin, multiphase C/Fe3C/MgO nanomaterials are formed, which are then etched to produce active carbon electrocatalysts with accessible trimodal porosity. These show remarkable performance in the oxygen reduction reaction – a key process in proton exchange membrane fuel cells. The activity is comparable to commercial platinum catalysts and shows improved stability with reduced crossover effects. This simple method offers a new route to widely applicable porous multicomponent nanocomposites.