On the basis of the evolutionary methodology for crystal structure prediction, the potential crystal structures of magnesium carbide with a chemical composition of Mg2C are explored. Except the known cubic phase (Fm3̅m), two novel tetragonal structures (P42/mnm and I41/Amd) and two novel hexagonal structures (P63/mmc and P6̅M2) of Mg2C are found. All these four new phases are mechanically and dynamically stable by the calculated elastic constants and phonon dispersions. Furthermore, the effects of pressure and temperature on the phase transitions among different Mg2C polymorphs are investigated, implying that some new phases especially the P42/mnm phase may be synthesized in future. The ratio values of B/G are also calculated in order to analyze the brittle and ductile nature of these Mg2C phases. In addition, electronic structure calculations suggest that the I41/Amd phase is semimetallic and the other three new phases are all metallic, which is different from the previously proposed magnesium carbides. Meanwhile, the calculated electronic density maps reveal that strong ionic bonding exists between the Mg and C atoms.