A new carbon nanofiber codoped with nitrogen and phosphorus (NPCNF) that has a high specific surface area and good electrocatalytic properties for the oxygen reduction reaction (ORR) was synthesized using a template-free method. The fabrication process involves the pyrolysis of phytic acid doped polyaniline aerogel. A nonaqueous Li-O2 battery with a specific capacity as high as 12 607 mA h g−1 was constructed by using an oxygen electrode based on NPCNFs supported by Ni foam. The NPCNF electrode showed a lower overpotential than pure carbon. The observed excellent electrochemical performance could be because of the unique foamlike N- and P-codoped carbon microstructure, which had a high ORR catalytic activity. These results indicate that the use of NPCNF as a cathode material could be a feasible approach to obtain a high-capacity Li–O2 battery.