A ternary composite was prepared by calcinating Ti3C2 MXene at different temperature, and then doping different contents of TiN nanoparticles on the calcinated MXene sheets. The nanocomposites were characterized by X-ray diffraction, scanning electron microscope, transmission electron microscope and X-ray photoelectron spectroscopy. UV–visible spectroscopy was used to investigate the optical properties of the composites. The results demonstrated that the calcinated MXene at temperature 450 °C had the best photocatalytic activity for the methylene blue under UV-light illumination compared with the other temperatures, due to existence of proper amounts of anatase and rutile TiO2 and intimate contact with MXene. After doping 4 wt% TiN, the absorption peak of the ternary composite in the visible light range further shifts redly, and the energy bandgap decreases compared with the calcinated MXene. The ternary composite photoanode coupled with 304 stainless steel (304 SS) exhibited certain photocathodic protection effect with its potential shifting negatively compared to natural corrosion potential of the 304 SS under simulated solar light illumination. Besides, protection without illumination is also demonstrated because of its lower potential than that of the 304 SS. The enhanced photocathodic protection performance of the ternary composite photoanode are attributed to the intimate contact of MXene and TiO2, as well as the ‘hot’ electrons and photothermal effect of the TiN due to localized surface plasmonic resonance effect, accelerating the electrons migration from TiO2 to Ti3C2.