In this work, a novel ZnO/g-C3N4 heterojunction catalyst was prepared by a thermal polycondensation process and has been applied for H2O2 production and in situ sterilization in natural waters irradiated by simulated sunlight. The H2O2 production efficiency of this process was measured, and its in situ sterilization ability in natural waters was evaluated. In addition, the remaining sterilization ability of the process was also assessed. The ZnO/g-C3N4 heterojunction catalyst with 10 wt% ZnO exhibited the best performance in H2O2 production of 5312.45 μmol·L−1 after 8 h, which was nearly 2.65 times greater than that of pure g-C3N4. Moreover, the bactericidal rate reached 97.4% on 10% ZnO/g-C3N4 after 60 min, while 47.3% on pure g-C3N4. H2O2 and sunlight alone had limited bactericidal effects, only 10.3% and 27.6%. It was proven that the H2O2 generated in situ achieved high-efficiency bacterial inactivation through the effect of sunlight excitation. ·OH and ·O2– were verified to play main roles in the inactivation of bacteria, which contributed to about 44.2% and 40.4% respectively. In addition, the mold was completely inactivated after 20 min and had similar mechanism of bacterial inactivation, showing good applicability of this process. This work may provide new ideas for realizing the in situ disinfection using sunlight as driving force and cleaning treatment of natural water bodies.