Using density functional theory within GGA approximation, the structural and elastic properties of two important phases (Mg17Al12 and Mg24Y5) in Mg-based alloys have been studied. The obtained equilibrium structural parameters for both phases agree very well with experimental data. The calculated negative cohesive energy and formation energy show that both cubic precipitates have strong structural stability as well as good alloying ability. Three independent single-crystal elastic constants (C11, C12 and C44) at zero pressure as well as polycrystalline mechanical parameters such as bulk modulus B, shear modulus G, Young's modulus E, Poisson's ratio ν and anisotropy value A for both phases have been calculated. The mechanical properties of the cubic phases such as ductility and tenacity are further analysed and discussed.