Nitrogen- and oxygen-containing hierarchical porous carbon frameworks have been successfully synthesized by carbonization and simultaneous activation of polyaniline with KOH as activating agent. The obtained porous carbon frameworks with hierarchical pore structures show high specific surface area (2280.0m2 g−1), large total pore volume (1.75cm3 g−1), and abundant nitrogen (5.7 at.%) and oxygen (14.4 at.%) functional groups. As expected, the porous carbon frameworks synthesized with a KOH/polyaniline weight ratio of 4:1 exhibit improved capacitance properties, such as an enlarged specific capacity (428.1Fg−1 at 0.5Ag−1), excellent rate capability (299.7Fg−1 at 50Ag−1), and excellent cycling stability. The specific power density and energy density can reach 14275Wkg−1, and 18.6Whkg−1, respectively. This method is facile, low cost, and effective for the production of nitrogen- and oxygen-containing carbon materials with high specific surface area, which can be applied in high-performance supercapacitors.