The effects of heavy metals on soil microbial communities have been extensively investigated, whereas the combined effects of heavy metals and nutrients on soil microbial communities and their interactions are rarely understood. In this study, we investigated the distribution patterns of heavy metals, nutrients and microbial communities in a typical contaminated farmland and explored their interaction mechanisms. The results showed that Cd and Pb were the main pollutants in this area, which mainly came from the smelter. Canonical correspondence analysis and variance decomposition analysis showed that the heavy metals played a more important role in restraining the microbial community structure of soils than other soil properties. Soil Cd, Pb, pH and available K content were the most important environmental factors affecting the microbial community structures in soil. Major Cd tolerant bacteria and fungi were detected including Actinobacteriota, Gemmatimonadota, Entorrhizomycota and Mortierellomycota. The analyses of molecular ecological networks showed that there were 84.1 % of negative correlations among microorganisms. Cd could regulate the abundance of key nodes in Cd-tolerant network modules, and these key nodes could improve the adaptability of the whole module to heavy metals through competition with other microorganisms. This study provides insights into the ecological effects of heavy metals and nutrients on soil microbial communities and will help to develop the bio-remediation technologies for contaminated soils.