Plasma electrolytic oxidation (PEO) is a promising surface treatment for generating a thick, adherent coating on valve metals using an environmentally friendly alkaline electrolyte. In this study, the PEO method was used to modify the surface of AZ31 Mg alloy. The composite coatings were formed in a phosphate-based electrolyte containing hydroxyapatite nanoparticles (NPs) and different concentrations (1, 2, 3, and 4 g/L) of TiO2 NPs. The results showed that the incorporation of TiO2 NPs in the composite coatings increased the porosity, coating thickness, surface roughness, and surface wettability of the coatings. The corrosion-resistance results of coatings in simulated body fluid (SBF) were tested for up to 72 h and all coatings showed superior corrosion resistance compared to the bare substrate. Among samples containing TiO2, the sample containing 1 g/L TiO2 had the highest inner layer resistance (0.51 kΩ·cm2) and outer resistance (285 kΩ·cm2) and the lowest average friction coefficient (395.5), so it had the best wear and corrosion resistance performance. The antibacterial tests showed that the higher the concentration of TiO2 NPs, the lower the adhesion of bacteria, resulting in enhanced antibacterial properties against S. aureus. The addition of 4 g/L of TiO2 NPs to the electrolyte provided an antibacterial rate of 97.65% for the coating.