We extend a nuclear ab initio framework based on chiral two- and three-nucleon interactions to investigate shape coexistence and the degradation of the π = 20 magic number in both even-even and odd-even magnesium isotopes. The quantum-number projected generator coordinate method, combined with the in-medium similarity renormalization group (IMSRG), is employed to compute their low-lying states. This approach reasonably reproduces the coexistence of weakly and strongly deformed states at comparable energies, and allows us to track the emergence of the π = 20 island of inversion through the continuous IMSRG evolution of the chiral Hamiltonian. Our results indicate that the ground state of 33Mg with spin-parity 3/2β is predominantly a strongly deformed configuration with πΎπ = 3β2β, while the lowest 7β2β state is predicted to be a shape isomer, consisting of a mixture of weakly deformed configurations with different πΎ values. The results highlight the essential roles of both dynamical and static collective correlations in reproducing the ordering of nuclear states with distinct shapes.