Transforming municipal sludge (MS) into biochar via co-pyrolysis with calcium salts enhances phosphorus (P) recovery and reduces the risk of heavy metal contamination. In this study, the performance and mechanism of bioavailable P conversion and heavy metal stabilization were systematically compared under co-pyrolysis of MS with CaCO3, CaO, and CaCl2 at mass ratios of 2.5-10 % at 700 degrees C. The results showed that CaCl2 had the best ability to convert P from non-apatite inorganic P to apatite P, followed by CaO and then CaCO3. CaO and CaCO3 addition induced more Ca5(PO4)3OH formation, while CaCl2 induced more Ca2PO4Cl and Ca5(PO4)3Cl formation. The degree of stabilization of heavy metals (e.g., Cd, Cr, Cu, Ni, Pd, and Zn) was significantly improved after co-pyrolysis of MS with these salts, thus reducing the potential environmental risk. In particular, because of the dual action mechanism of chloride ions and calcium ions, co-pyrolysis with CaCl2 exhibited the lowest risk of heavy metal contamination compared with CaCO3 and CaO. These findings suggest that addition of 2.5 % CaCl2 can optimize the production of bioavailable P and the stabilization of heavy metals in biochar. This treatment is recommended for the safe utilization of P resources derived via MS pyrolysis.