Oxygen reduction reaction (ORR) is one of the most important processes in energy conversion and conservation such as in fuel cells, metal–air batteries and water-splitting devices. In this work, hierarchical porous N-doped graphene foams (HPGFs) functioned by a transition metal were successfully prepared using silica nanoparticles as a template. The introduction of a silica template and a transition metal provided HPGFs with a large specific surface area (918.7m2/g) and abundant active sites. By selecting proper nitrogen precursors (cyanamide, melamine and urea), HPGFs exhibit excellent ORR catalytic activity in 0.1M KOH with a high onset potential of 1.03V and a limiting current of ∼9mAcm−2, even better than that of commercial Pt/C catalysts at the same loading. Surprisingly, they show superior catalytic activity in an acidic medium with an onset potential of 0.81V and a limiting current reaching ∼10mAcm−2. Furthermore, the catalysts deliver good methanol tolerance and excellent long term durability after 5000 cycles of accelerated durability tests in both acidic and alkaline solutions, much better than that of a commercial Pt/C catalyst. Very inspiring cell performance was observed with HPGF-1 catalyst upon integration into a zinc–air battery. Our study presents an experimental realization of rationally designing a highly efficient ORR electrocatalyst for electrochemical energy conversion systems particular to fuel cells and metal–air batteries.