The Co–N–C catalyst has exhibited its effectiveness as a substitute for the 2e− ORR in the synthesis of H2O2. However, it still exhibits low selectivity towards 2e− ORR. In this work, the P doped Co–N–C (Co–N/P–C) electrocatalysts with enhanced performance for H2O2 production were synthesized through in situ P-doping method. Moreover, the P content of Co–N/P–C was varied to investigate its correlation with H2O2 selectivity. The results revealed that P doping greatly enhanced both selectivity and yield of H2O2. Under acidic conditions (pH = 1), Co–N/P–C-0.75 exhibited optimal 2e− ORR performance (H2O2 yield of 174 mmol g−1 h−1, H2O2 selectivity of 34.39%, electron transfer (n) of 3.31), significantly outperforming the P-free Co–N–C catalyst (H2O2 yield of 64 mmol g−1 h−1, H2O2 selectivity of 10.81%, n of 3.78). Additionally, Co–N/P–C-0.75 based electron-Fenton process showed attractive performance for rhodamine B (RhB) degradation, whose degradation rate was two times higher than that of Co–N–C. The experimental findings revealed that the improved efficiency of Co–N/P–C-0.75 could be attributed to the substitution of coordinated N atom with less electronegative P atom, which enhanced the electron density around the Co atom and facilitated *OOH desorption for H2O2 production.