In this study, we prepared a novel three-dimensional boron-doped diamond (BDD) electrode. Subsequently, we systematically conducted an electrochemical oxidation reaction on sulfamethoxazole (SMX) using a BDD anode and a platinum plate (Pt) cathode. The effects of initial concentration, current density, initial pH, and carrier electrolyte on SMX degradation were investigated. The SMX was completely removed after 4 h of electrolysis at a current density of 30 mA/cm2, 0.1 mol sodium sulphate as the supporting electrolyte, and a pH of 7. Additionally, the COD removal rate was 65.6 %, while the energy consumption was 40.1 %. Compared with two-dimensional BDD electrode degradation, the energy saving was 54 %. Density functional theory (DFT) and high-performance liquid chromatography (HPLC) were used to analyse the SMX degradation mechanism. Three possible degradation pathways were proposed: ·OH substitution of the amino group in the aromatic ring, oxidation of the amino group to nitrogen dioxide, and addition of ·OH to the isoxazole ring. The active sites detected in the reaction corresponded closely with the calculated results using DFT. Moreover, ECOSAR toxicity analysis was applied to evaluate the toxicity of the intermediates produced during electrolysis. We discovered that the toxicity of SMX and its intermediates decreased significantly during electrolysis.