Sewage sludge (SS), as a phosphorus (P)-rich wet biomass, can generate a large number of P-containing high-value by-products after converted to biofuel by hydrothermal liquefaction (HTL). However, the potential mechanisms of migration and transformation of phosphorus in this process are unclear due to the complexity of SS composition and HTL processes. In this work, Gradient Boosting Regression (GBR) algorithm was employed in machine learning (ML) models to investigate the impacts of input features on the phosphorus content and forms during HTL. Machine learning models showed good performance with an average training R2 > 0.95 and an average testing R2 > 0.85. Further, representative HTL conditions including temperature (270–350 °C) and residence time (20–60 min) were selected for experiment validation of studied mechanisms. The results indicated that with temperature and time increasing, phosphorus recovery (R_P) increased from 86.85 % to 92.65 % and the relative content of apatite inorganic phosphorus in hydrochar (APRC_HC) increased from 33.67 % to 39.06 %. The relative content of inorganic phosphorus in hydrochar (IPRC_HC) stabilized at 98 % at above 270 °C. 85 % of phosphorus in SS migrated to hydrochar after HTL, and most of P was in the form of IP. Ca3(PO4)2 and Ca4P6O19 were detected by X-ray diffraction (XRD). This information can provide significant theoretical support for phosphorus resource recovery in hydrochar derived from HTL of SS.