Due to the effective removal of refractory organic pollutants, advanced oxidation technology based on sulfate radicals (SO4·-) has attracted widespread attention. However, it is still a challenge to design an eco-friendly catalyst that efficiently activates persulfate. In this paper, oxygen-doped porous graphitic carbon nitride (OCN) was prepared by a simple thermal polymerization method to activate persulfate for removing the stubborn drug carbamazepine and showed a good removal effect. Compared with the pristine g-C3N4, the catalytic performance of OCN increased by 5.6 times under dark conditions and 4.1 time under visible light irradiation conditions, respectively. Under dark conditions, oxygen doping mainly modulated the electronic structure of the catalyst to provide more active sites to enhance persulfate activation. Under visible light conditions, oxygen doping reduced the band gap and introduced impurity defect energy level, so that the light absorption capacity was improved and photo-generated carriers were effectively separated. The results of electron paramagnetic resonance and active species trapping experiments showed that the combined action of free radicals and non-radical oxidation pathways was the main mechanism of carbamazepine degradation. Therein, singlet oxygen (1O2) was the main active species, followed by O2·- and SO4·−. In addition, environmental factor experiments showed that chloride ions, bicarbonate ions and humic acid all had significant promoting effects, and there were other interactions between humic acid and carbamazepine besides adsorption to promote the degradation reaction. Finally, high-resolution mass spectrometry identified that ring condensation, hydroxylation and carboxylation were the primary degradation pathways of carbamazepine. This work provides a feasible way for designing high-efficiency and pollution-free persulfate activators to remove refractory pollutants.