© The Royal Society of Chemistry 2020. Multiple heteroatom-doped carbons with 3D ordered macro/meso-microporous structures have not been realized by simple carbonization of metal-organic frameworks (MOFs). Herein, ordered macroporous phosphorus- and nitrogen-doped carbon (M-PNC) is prepared successfully by carbonization of double-solvent-induced MOF/polystyrene sphere (PS) precursors accompanied with spontaneous removal of the PS template, followed by post-doping. M-PNC shows a high specific surface area of 837 m2g−1, nitrogen doping of 3.17 at%, and phosphorus doping of 1.12 at%. Thanks to the hierarchical structure, high specific surface area, and multiple heteroatom-doping, M-PNC exhibits unusual catalytic activity as an electrocatalyst for the oxygen reduction reaction. Computational calculation reveals that the PO group helps stabilize the adsorption of intermediates, and the position of PO relative to graphitic N significantly improves the activity of the adjacent carbons for electrocatalysis.