Three-dimensional (3D) hierarchical porous Co-containing N-doped carbon materials (HP-Co-CNs) have been successfully prepared for the first time by using cyanamide as a nitrogen source and poly(vinyl alcohol) (PVA) hydrogel-based composites as in situ templates. Remarkably, the resulting HP-Co-CNs possess controllable nitrogen content, high surface area, hierarchical interconnected macro-/mesoporous structure, and a certain amount of Co-Nx moieties which could act as active sites in the oxygen reduction reaction (ORR). In studying the application of HP-Co-CNs for the ORR, the HP-Co-CNs showed excellent electrocatalytic performance for a four-electron ORR, and longer-term stability and higher methanol tolerance then the commercial Pt/C electrocatalyst in alkaline medium, highlighting the importance of macropores for diffusion and a sufficient amount of active sites related to high specific surface area for improving the ORR performance.