Nitrogen-enriched hierarchically porous carbons (HPCs) were synthesized from a novel nitrile-functionalized benzoxazine based on benzoxazine chemistry using a soft-templating method and a potassium hydroxide (KOH) chemical activation method and used as electrode materials for supercapacitors. The textural and chemical properties could be easily tuned by adding a soft template and changing the activation temperature. The introduction of the soft-templating agent (surfactant F127) resulted in the formation of mesopores, which facilitated fast ionic diffusion and reduced the internal resistance. The micropores of HPCs were extensively developed by KOH activation to provide large electrochemical double-layer capacitance. As the activation temperature increased from 600 to 800 °C, the specific surface area of nitrogen-enriched carbons increased dramatically, micropores were enlarged, and more meso/macropores were developed, but the nitrogen and oxygen content decreased, which affected the electrochemical performance. The sample HPC-800 activated at 800 °C possesses a high specific surface area (1555.4 m(2) g(-1)), high oxygen (10.61 wt %) and nitrogen (3.64 wt %) contents, a hierarchical pore structure, a high graphitization degree, and good electrical conductivity. It shows great pseudocapacitance and the largest specific capacitance of 641.6 F g(-1) at a current density of 1 A g(-1) in a 6 mol L(-1) KOH aqueous electrolyte when measured in a three-electrode system. Furthermore, the HPC-800 electrode exhibits excellent rate capability (443.0 F g(-1) remained at 40 A g(-1)) and good cycling stability (94.3% capacitance retention over 5000 cycles).