Mg alloys are attractive materials for medical devices. The main limitation is that they are prone to corrosion. A low toxicity surface coating that enables uniform, controlled corrosion at a desired rate (this usually means it must offer barrier functions for a limited time period) is desirable. Phosphate-based ionic liquids (ILs) are known to induce a coating that can reduce the corrosion rate of Mg alloys, Furthermore, some ILs are known to be biocompatible and therefore, controlling the corrosion behaviour of an Mg alloy and its surface biocompatibility can be achieved through adding an appropriate low toxic IL surface layer to the substrate. In this study, we have evaluated the cytotoxicity of three phosphate-based ILs to primary human coronary artery endothelial cells. Among them, tributyl(methyl)-phosphonium diphenylphosphate (P1,4,4,4dpp) shows the lowest cytotoxicity. Therefore, further work was aimed at developing an appropriate treatment method to produce a homogeneous and passive surface coating based on P1,4,4,4dpp IL, with the focus on investigating the effect of treatment time. The results showed that that the formation of IL coating on AZ31 has proceeded progressively, and treatment time plays an important role. An IL treatment at 100 °C with an extended treatment time of 5 h significantly enhanced corrosion resistance of the AZ31 alloy in simulated body fluid. Additionally, the corrosion morphology was uniform and there was no evidence of “localized pitting corrosion” observed. Such a performance makes this ionic liquid coating as a potential surface coating biodegradable Mg-based implants.