The interactive effects between the emerging contaminant antibiotic resistance genes (ARGs) and the traditional pollutant total petroleum hydrocarbons (TPHs) in contaminated soils remain unclear. The synergistic removal of TPHs and ARGs from composted contaminated soil, along with the microbial mechanisms driven by the addition of biogas slurry, have not yet been investigated. This study explored the impact of biogas slurry on the synergistic degradation mechanisms and bacterial community dynamics of ARGs and TPHs in compost derived from contaminated soil. The addition of biogas slurry resulted in a reduction of targeted ARGs and mobile genetic elements (MGEs) by 9.96%–95.70% and 13.32%–97.66%, respectively. Biogas slurry changed the succession of bacterial communities during composting, thereby reducing the transmission risk of ARGs. Pseudomonas, Cellvibrio, and Devosia were identified as core microorganisms in the synergistic degradation of ARGs and TPHs. According to the partial least squares path model, temperature and NO3− indirectly influenced the removal of ARGs and TPHs by directly regulating the abundance and composition of host microbes and MGEs. In summary, the results of this study contribute to the high-value utilization of biogas slurry and provide methodological support for the low-cost remediation of contaminated soils.