A porous graphene layers with a three-dimensional structure (3DG) was prepared via a gas foaming method based on a polymeric predecessor. This intimately interconnected 3DG structure not only significantly increases the specific surface area but also provides more channels to facilitate electron transport. In addition, 3D N-doped (3DNG) layers materials were synthesized using melamine as a nitrogen source. The nitrogen content in the 3DNG layers significantly influenced the electrochemical performance. The sample denoted as 3DNG-2 exhibited a specific capacitance of 335.2Fg−1 at a current density of 1Ag−1 in a three-electrode system. Additionally, 3DNG-2 exhibited excellent electrochemical performance in aqueous and organic electrolytes using a two-electrode symmetric cell. An energy density of 58.1Whkg−1 at a power density of 2500Wkg−1 was achieved, which is approximately 3 times that (19.6Whkg−1) in an aqueous electrolyte in a two-electrode system. After 1000 cycles, the capacity retention in aqueous electrolyte was more than 99.0%, and this retention in organic electrolytes was more than 89.4%, which demonstrated its excellent cycle stability. This performance makes 3DNG-2 a promising candidate as an electrode material in high-power and high-energy supercapacitor applications.