Deciphering the impact of single and combined contamination of total petroleum hydrocarbons (TPH) and heavy metals on soil microecosystems is essential for the remediation of contaminated habitats, yet it remains incompletely understood. In this study, we employed high-throughput sequencing to investigate the impact of single TPH contamination, single metal contamination, and their co-contamination on soil microbial diversity, assembly mechanisms, composition, ecological function, and resistome. Our results revealed that contamination led to a reduction in alpha diversity, with single contamination displaying lower diversity compared to co-contamination, depending on the concentration of pollutants. Community beta diversity was primarily driven by turnover rather than nestedness, and narrower ecological niches were detected under pollution conditions. The neutral community model suggested that homogenizing dispersal played a significant role in the community assembly process under single TPH or co-contamination, while homogeneous selection dominated under heavy metals pollution. Procrustes analysis demonstrated a correlation between community composition and functional divergence, while Mantel tests linked this divergence to concentrations of Cr, Cr6+, Pb, and TPH. Interestingly, soils co-polluted with TPH and heavy metals exhibited similar genera, community functions, and resistomes as soils contaminated with only metals, highlighting the significant impact of heavy metals. Ecological functions related to carbon (C), nitrogen (N), and sulfur (S) cycles were enhanced under TPH pollution but impaired under heavy metals stress. These findings enhance our understanding of soil microecosystems subjected to TPH, heavy metals, and their co-contamination, and carry significant implications for environmental microecology and pollutant risk assessment.