Osteosarcoma (OS) is the most prevalent primary malignancy of bone. Inhibition of OS recurrence and subsequent bone formation after surgery remains a challenge for decades. Innovative biomaterials with the dual function of tumor therapy and bone regeneration have emerged as a promising strategy for OS treatment. We developed a bioactive nanoparticle (MDA-NPs) composed of magnesium oxide nanoparticle (M-NPs) core and 2-Aminoethyl methacrylate (2-AM) grafted polydopamine (PDAM) shell. The phosphonate modified methacrylamide chitosan (CMP) and polyacrylamide (PAM) were prepared to form a pre-gel, and then a series of MDA-NPs nanocomposite with 0 mg/mL, 0.5 mg/mL, 2.5 mg/mL, 5 mg/mL, and 10 mg/mL were incorporated and coded as CMP@PAM, 0.5NP/CMP@PAM, 2.5NP/CMP@PAM, 5NP/CMP@PAM, 10NP/CMP@PAM, respectively. We found that 5NP/CMP@PAM hydrogel showed a balanced photothermal effect, mechanical property, and osteogenesis for MDA-NPs can be used as a co-crosslinker, photothermal agent, and Mg2+ reservoir. Human OS cells (143B) could be efficiently inhibited by 5NP/CMP@PAM hydrogel with near-infrared (NIR) laser irradiation, achieving complete suppression of tumor recurrence in vitro and in vivo. The released Mg2+ efficiently promotes the osteogenic activities of mouse embryo osteoblast precursor cells (MC3T3-E1) and 5NP/CMP@PAM hydrogels exhibit highly effective bone repair performance in a critical cranial defect rat model. In conclusion, the 5NP/CMP@PAM hydrogel demonstrated excellent dual functions of suppressing OS recurrence and repairing bone defects. This novel multifunctional bioactive hydrogel provides an encouraging idea of synergistic postoperative treatment of OS.