A nitrogen and phosphorus co-doped hierarchical porous carbon (N, P-HPC) were fabricated by simply pyrolysis of polyaniline aerogels in the presence of phytic acid and subsequently activation treatment by KOH. The as-prepared N, P-HPC with a highly interconnected network structure and possesses a large surface area and pore volume is very favor in the impregnation of sulfur. Moreover, simultaneously introduced nitrogen and phosphorous into the carbon could create more active sites than the mono-doped carbons, the synergistic effects of dual activation of carbon atoms induced stronger chemical adsorption ability. Benefiting from the advantages of suitable hierarchical porosity, high conductivity, fast ion transportation, physical and chemical adsorption of the N, P-HPC, the Sulfur/N, P-HPC composite exhibits high initial discharge capacity of 1116 mAh g−1 at 0.1 C (1 C = 1675 mA g−1, based on sulfur content) and high rate capability of 550 mAh g−1 at 2C, as well as excellent long term cycling stability at a current rate of 1 C with only 0.058% capacity decay per cycle for over 500 cycles. Such a high capacity and stability suggests that the novel cathode have alluring prospect for Li-S batteries.