Traditional porous carbon obtained by potassium hydroxide activation are facing with complex preparation process, low heteroatoms content and sluggish ion-transport kinetics caused by their amorphous microporous structure. Herein, we develop a facile method to prepare heteroatom-doped hierarchical porous carbon (HPC) using magnesium oxide as template and polyacrylamide as raw material without any activation. MgO and polyacrylamide can be closely combined by electrostatic self-assembly, so as to give full play to the role of MgO template. The prepared samples exhibit three-dimensional (3D) interconnected hierarchical porous structure, large specific surface area (SSA) and a large amount of nitrogen (10.97 at.%) and oxygen (10.3 at.%) functional groups. Benefiting from their synergy, the optimized NHPC-700 electrode possesses a high specific capacitance of 295.3 F g −1 at 0.5 A g −1 , excellent rate characteristics and superior cycling performance (100.76 % capacitance retention after 10,000 cycles). Furthermore, the assembled NHPC-700//NHPC-700 symmetrical supercapacitor provides a high energy density of 15.16 Wh kg −1 in 1 M Na 2 SO 4 aqueous electrolyte. The results fully demonstrate that the obtained hierarchical porous carbon shows promising application in supercapacitors. • High content of heteroatom-doped 3D interconnected hierarchical porous carbon was synthesized. • The NHPC-700 electrode delivers large specific capacitance and great electrochemical stability. • The symmetrical supercapacitor shows high energy density and superior cycling stability.