Nitrosopyrrolidine (NPYR) is a nitrogenous disinfection by-products (N-DBPs) that has attracted much attention due to its high toxicity and resistance to treatment. The removal of NPYR using a three-dimensional aerated electrochemical reactor (3DAER) was investigated. The artificial neural network (ANN) method was employed for the first time to optimize the operating parameters of NPYR degradation with the 3DAER system. Compared to manual parameter optimization, the NPYR degradation parameters generated with the ANN increased the degradation rate by 8.20% to 86.67%. The inhibition rate of the treated water sample used to treat luminescent bacteria was reduced by 49.16%. Mechanistic studies revealed that ·OH and ·O2- were involved in the reaction, and ·OH attacked nucleophilic sites and ·O2- targeted the electrophilic sites of NPYR. Gas chromatographymass spectrometry (GC–MS), combined with Fukui index analyses, was used to elucidate the pathway for NPYR degradation. This confirmed lower biological toxicities for the intermediate products formed during NPYR degradation. In conclusion, the MgFe-LDH/3DAER electrochemical process mitigated the environmental hazards associated with NPYR. This study offers theoretical insights and practical guidance for controlling water disinfection by-products.