A near-infrared (NIR) light-induced shape memory-assisted self-healing coating was developed by incorporating Ti3C2 MXene and polyaniline (PANI) composites into epoxy resin. Ti3C2 thin nanosheets were obtained by etching Ti3AlC2 powders with HCl and LiF and then intercalating with tetramethylammonium hydroxide. Then MXene@PANI composites were synthesized through chemical oxidation. Result of ultraviolet–visible spectroscopy showed two obvious characteristic peaks at visible and NIR light range, indicating that the MXene@PANI composite could be used as photothermal agents to induce shape memory effect of the epoxy resin. Results of electrochemical impedance spectra and scanning vibrating electrode technique indicated that the addition of 5 wt% MXene@PANI to the epoxy resin coating could improve its protection performance, and own 91% self-healing efficiency due to the NIR absorbing ability of MXene and PANI and the passivation of PANI. Linear scanning voltammetry measurements indicated that the shape memory effect and self-healing performance of the epoxy resin matrix were affected by the corrosion product in the scratched area.