Antibiotics in animal manure pose significant risks to the environment and health. While anaerobic digestion (AD) is commonly used for pig manure treatment, its efficiency in antibiotic removal has been considerably limited. This study investigated the impact of hydrothermal pretreatment (HTP) on sulfadiazine (SDZ) removal in a two-stage AD system. Results indicated that the HTP process reduced SDZ concentration by 40.61%. Furthermore, the SDZ removal efficiency of the AD system coupling HTP increased from 50.90% to 65.04% compared to the untreated system. Biogas yield was also improved by 26.17% while maintaining system stability. Changes induced by HTP in the microbial communities revealed that Firmicutes, Bacteroidetes, Caldatribacteriota, and Proteobacteria emerged as the primary bacterial phyla. Following HTP, the relative abundance of Prevotella, which exhibited a strong negative correlation with SDZ concentration, increased significantly by 25-fold in the acidogenic stage. Proteiniphilum, Syntrophomonas and Sedimentibacter showed notable increases in the methanogenic stage after HTP. The N-heterocyclic metabolism carried out by Prevotella might have been the predominant SDZ degradation pathway in the acidogenic stage, while the benzene ring metabolism and hydroxylation by the Proteiniphilum emerged as the primary degradation pathways in the methanogenic stages. Furthermore, biodegradation intermediates were proven to be less toxic than SDZ itself, indicating that the HTP-enhanced two-stage AD process could be a viable way to lower the environmental risks associated with SDZ. The findings from this study provide valuable insights for removing SDZ from the environment via two-stage AD.