Metal-organic framework [MOF, i.e., NH2-MIL-53(Al)] modified TiO2 (NMT) composite photoanodes were successfully prepared by hydrothermal synthesis and were used for the photoelectrochemical cathodic protection (PECCP) of nickel-plated magnesium alloy (Mg/Ni). Results showed that the synthesis temperature significantly impacted the morphology and PECCP performance of the NMT photoanodes. The NMT@150 photoanode prepared at a reaction temperature of 150°C exhibited the best PECCP performance and produced a current density of 1980 μA cm−2 under visible light irradiation, which was 19.8 times higher than that of a single TiO2 photoanode. The composite photoanode could polarize the open circuit potential of the coupled Mg/Ni electrode to −876 mV and remain relatively stable within 35 h. XPS and EPR tests showed that a Z-scheme heterojunction was formed between the NH2-MIL-53(Al) and TiO2 nanotubes, allowing the photogenerated electrons to accumulate mainly on the conduction band of NH2-MIL-53(Al). The heterojunction greatly promoted the separation and transfer of photogenerated electron-hole in the NMT composite photoanode, significantly enhancing the PECCP performance for Mg/Ni.