The ab initio approach is developed that allows predicting structural changes, which can be induced by Plasma Immersion Ion Implantation (PIII) of Ag ions into Mg based alloys. The calculations are performed in the framework of the density functional theory. The approach is based on the assumption that the electronic properties of the irradiated parent phase predetermine the structural characteristics of a new implantation-induced phase. It is presumed that penetration of the implanted ions into the host lattice leads, firstly, to "immediate" excitation of the electronic subsystem of the parent phase. Then this initial stage is followed by changes of the atomic configuration so that the electronic subsystem transfers to the relaxed state. To characterize and to quantify how the initial non-equilibrium state is far from the quasi-relaxed state of the system, the energy parameter ΔE is proposed. The behaviour of ΔE plot vs. different concentrations of implanted ions correlates with the conditions of formation of the new phase. The correctness of the proposed approach was corroborated by ab-initio analysis of the experimentally observed phase transitions Mg + Agions → MgAg and Mg17Al12 + Agions → Mg 54Al28Ag18 induced by PIII treatment.