Modification of the microenvironment of metal- and nitrogen-coordinated nanocarbons (M-N-Cs) is critical in regulating their electronic structure and thus catalytic selectivity toward the oxygen reduction reaction (ORR). Introducing heteroatoms into the carbon matrix of M-N-Cs could affect the coordination configuration and charge density of the metal centers, but it has rarely been applied to improve the ORR selectivity for H2O2 electrosynthesis. Here we show that doping phosphorus (P) atoms into the carbon substrate of a Co-N-C catalyst lengthens the Co−N bond, decreases the electron density of the Co, and weakens the adsorption strength of the key *OOH intermediate on the active sites, as demonstrated by both experimental and theoretical results. Consequently, this P-doped Co-N-C catalyst presents outstanding catalytic performance toward the 2e− ORR with an early onset potential of 0.81 V (vs. the reversible hydrogen electrode), exceptional H2O2 selectivity above 90% in a wide potential range from 0.1 V to 0.7 V (maximum value of ∼ 97% at 0.5 V) and a large turnover frequency (2.36 ± 0.15 s−1 at 0.65 V) in alkaline electrolyte, superior to almost all previously reported counterparts. Moreover, an unprecedented H2O2 production rate up to 11.2 molH2o2gcatalyst−1h−1 with long-term durability (110 h) is obtained when the catalyst is assessed as a gas diffusion layer in a practical flow cell.