In recent decades, nitrogen-containing heterocyclic compounds (NHCs) have been widely synthesized and applied due to their excellent coordination capability of heterocyclic N atoms. However, their high toxicity and poor biodegradability pose significant hazards to aquatic ecosystems. Three characteristic NHCs (cNHCs) with similar molecular structures but minor differences in the number and position of N atoms, namely benzotriazole (BTA), benzimidazole (BMZ), and indazole (IDZ), were selected to evaluate impacts of these differences on their degradation behaviors during UV/H2O2 treatments. It was found that the key mechanism for the removal of BTA, BMZ, and IDZ in the UV/H2O2 processes was the generation of ∙OH through UV-excited H2O2 decomposition. Density functional theory (DFT) calculations revealed that the variation in the number and position of heterocyclic ring N atoms significantly affected the electron cloud distribution of the cNHCs, thereby resulting in different reactivities. Mineralization results and N evolution experiments indicated that N elements were initially released in the form of ammonia nitrogen during UV/H2O2 treatments, which then underwent oxidation to form nitrite and nitrate. The two ortho-N atoms were most easily mineralized and release inorganic nitrogen, followed by the two meta-N atoms. However, the BTA compound containing three N atoms, exhibited inertness towards radicals after hydroxylation, thereby hindering mineralization. A dual-directional transformation products (TPs) identification protocol was employed to identify 30 TPs of the cNHCs and propose recommended degradation pathways. Furthermore, Vibrio fischeri bioluminescence inhibition bioassay and QSAR prediction models were used to preliminarily screen and identify 13 toxic TPs with potential ecological risks.