Nitrogen-containing hierarchically porous carbon is derived by carbonizing and activating polypyrrole nanostructure (APNP) using a template-free synthesis method and is demonstrated to be an efficient counter electrode (CE) in dye-sensitized solar cells (DSSCs). APNP exhibits an interconnected hierarchical pore structure with a pore volume of 0.52 cm3 g-1 and a large specific surface area of 707.98 m2 g-1. The material also displays a low degree of graphitization phase as well as numerous defects. The sheet resistance and conductivity of the APNP CE film are 2.05 × 103 Ω sq-1 and 35.86 S m-1, respectively. Electrochemical catalytic activity and photovoltaic performance studies demonstrate that APNP exhibits significant catalytic activity towards triiodide (I3-) reduction and shows power conversion efficiency (PCE) of 6.58%, which is comparable to Pt-based DSSCs (6.93%). We observed that, apart from improving the surface area and pore structure, the chemical activation process increases defect sites, conductivity and the graphitic N state, hence reduces the charge transfer resistance in the CE, and finally enhances the PCE of the DSSC. © 2016 The Royal Society of Chemistry.