Phosphorus recovery from wastewater is a vital pathway toward sustainable phosphorus utilization. This study established an effective process for simultaneous nitrogen removal and phosphorus recovery by anammox coupled with magnesium phosphate (MP) crystallization. A high removal efficiency of nitrogen (88.5%) and phosphorus (83.8%) was achieved, with the highest nitrogen removal rate and phosphorus removal rate reaching 1.349 kg/(m 3 d) and 0.083 kg/(m 3 d), respectively. Theoretical calculation and experimental validation demonstrated that MP cannot precipitate under abiotic conditions. MP formation is intricately linked to microbial activity, including the ion reservoir effect of microbial consortia, anammox reaction, and conversion of struvite to MP promoted by anammox bacteria (AnAOB). Meanwhile, the granular sludge with biofilm attached to an inorganic core was obtained. Metagenomic analysis revealed that Candidatus Jettenia caeni replaced Candidatus Kuenenia stuttgartiensis as the prevailing AnAOB under the biomineralization environment, and its maximum relative abundance was 15.48%. Concurrently, correlating to gene up or down regulation, the increases in anammox activity and extracellular protein secretion as well as decreases in cell Mg intake were advantageous to MP formation. These findings provided insights into the interaction between microorganisms and crystal formation, highlighting the significance of anammox bacteria and their symbiotic counterparts in the process.