Magnesium chloride (MgCl2) with the rhombohedral layered CdCl2-type structure (α-MgCl2) has been studied experimentally using synchrotron angle-dispersive powder x-ray diffraction and Raman spectroscopy using a diamond-anvil cell up to 100 GPa at room temperature and theoretically using first-principles density functional calculations. The results reveal a pressure-induced second-order structural phase transition to a hexagonal layered CdI2-type structure (β-MgCl2) at 0.7 GPa: the stacking sequence of the Cl anions are altered resulting in a reduction of the c-axis length. Theoretical calculations confirm this phase transition sequence and the calculated transition pressure is in excellent agreement with the experiment. Lattice dynamics calculations also reproduce the experimental Raman spectra measured for the ambient and high-pressure phase. According to our experimental results MgCl2 remains in a 2D layered phase up to 100 GPa and further, the 6-fold coordination of Mg cations is retained. Theoretical calculations of relative enthalpy suggest that this extensive pressure stability is due to a low enthalpy of the layered structure ruling out kinetic barrier effects. This observation is unusual, as it contradicts with the general structural behavior of highly compressed AB2 compounds.