The six dimensional potential energy surface of the electronic ground state X̃(1)Σ(g)(+) of Mg(2)H(2) has been generated by the coupled-cluster approach with single, double and perturbative triple excitations [CCSD(T)] combined with the aug-cc-pCVTZ basis set for Mg atoms and the aug-cc-pVTZ basis set for the H atoms. The analytical representation of this surface was used in variational calculations of the rovibrational energies of Mg(2)H(2), Mg(2)D(2), and HMg(2)D for J = 0 and 1. For Mg(2)H(2), the rotational constant B(0) is computed to be 0.1438 cm(-1), and the fundamental anharmonic wavenumbers are calculated to be ν(1) = 1527.3 cm(-1) (Σ(g)(+)), ν(2) = 275.3 cm(-1) (Σ(g)(+)), ν(3) = 1503.6 cm(-1) (Σ(u)(+)), ν(4) = 312.9 cm(-1) (Π(g)), and ν(5) = 256.5 cm(-1) (Π(u)). In addition, the electronic ground states of Mg(2)H, MgH(2), Mg(2), and MgH have been investigated in order to compute the bonding energies of Mg(2)H(2) and to explain the strength of the Mg-Mg bond in this tetra-atomic molecule. The nature of the low-lying excited states of Mg(2)H(2) is also studied.