Biofilms, known as "microbial skin" in rivers, respond to rapid and sensitive environmental changes. However, the ecological response mechanisms of bacterial and fungal communities in river biofilms toward heavy metal pollution (HMP) remains poorly understood. This study focused on the key driving factors of bacterial and fungal community diversity and composition and their ecological response mechanisms within periphytic biofilms of Asia's largest Pb-Zn mining area. The diversity, dominant bacterial taxa, and bacteria structure in biofilms were influenced by biologically available heavy metal (HM) fractions, with Ni-F3 (17.96 %) and Pb-F4 (16.27 %) as the main factors affecting the bacterial community structure. Fungal community structure and α-diversity were more susceptible to physicochemical parameters (pH and nutrient elements). Partial least squares path modeling revealed that environmental factors influencing bacterial and fungal communities in biofilms were ranked as water quality > metal fractions > total metals. Dispersal limitation was the most critical ecological process in bacterial (56.9 %) and fungal (73.4 %) assembly. The proportion of heterogeneous selection by bacteria (39.5 %) was higher than that of fungus (26.2 %), which increased with increasing HMP. Bacterial communities had a higher migration rate (0.48) and ecological drift proportion (3.6 %), making them more prone to escape environmental stress. Fungal communities exhibited more keystone species, larger niche width (23.24 ± 13.04 vs. 9.72 ± 5.48), higher organization level, and a more stable co-occurrence network than bacterial communities, which enabled them to better adapt to high environmental pollution levels. These findings expanded the understanding of the spatiotemporal dynamics of microbial communities within biofilms in HM-polluted watersheds and provided new insights into the ecological responses of microbial communities to HMP.