Understanding the porosity of biochar (BC) that promotes the heavy metal (HM) passivation during composting can contribute to the sustainable management of pig manure (PM). The current work aimed to explore the influence of BC with varying pore sizes on the physicochemical properties and morphological changes of HMs (including Zn, Cu, Cr, As, and Hg), and microbiota development during PM composting. The various pore sizes of BC were generated by pyrolyzing pine wood at 400 (T1), 500 (T2), 600 (T3) and 700 (T4) C, respectively. The results revealed a positive correlation between specific surface area of BC and pyrolysis temperature. BC addition contributed to a significantly extended compost warming rate and duration of high-temperature period, as well as HM passivation, reflected in the decrease in Exc-Zn (63-34%) and Red-Cu (28-13%) content, and the conversion of Oxi-Cr (29-21%) and Red-Hg (16-5%) to more stable forms. Moreover, BC at T4 exhibited the best effect on Zn and Cu passivation due to the highest specific surface area (380.03 m(2)/g). In addition to its impact on HM passivation, BC addition improved the microbial environment during PM composting, leading to enhanced microbial diversity and richness. Notably, Chloroflexi and Bacteroidota played key roles in promoting the transformation of Exc-Cu and Red-Hg into stable forms. This phenomenon further stimulated the enhanced decomposition of organic matter (OM) when BC prepared at 600-700 C-degrees was added. Therefore, it can be concluded that the regulation of BC porosity is an effective strategy to improve HM passivation and the overall effectiveness of PM composting.