In order to improve the corrosion resistance and microhardness of AZ91D magnesium alloy, TiN nanoparticles were addedto fabricate Ni-P-TiN composite coating by electrodeposition. The surface, cross-section morphology and composition wereexamined using SEM, EDS and XRD, and the corrosion resistance was checked by electrochemical technology. The results indicatethat TiN nanoparticles were doped successfully in the Ni-P matrix after a series of complex pretreatments including activation, zincimmersion and pre-electroplating, which enhances the stability of magnesium alloy in electrolyte and the adhesion betweenmagnesium alloy and composite coating. The microhardness of the Ni-P coating increases dramatically by adding TiN nanoparticlesand subsequent heat treatment. The corrosion experimental results indicate that the corrosion resistance of Ni-P-TiN compositecoating is much higher than that of uncoated AZ91D magnesium alloy and similar with Ni-P coating in short immersion time.However, TiN nanoparticles play a significant role in long-term corrosion resistance of composite coatings.