The mechanism of specific cleavage of the terminal phosphoryl group in hydrolysis of ATP, and the role of Mg2+ in the hydrolysis were studied by ab initio molecular orbital calculations. The tetravalent anion of methyl triphosphate was used as a model of the ATP anion, and its electronic structures were determined as a function of the distance between Mg2+ and its beta-phosphoryl group. We found that the closer location of Mg2+ to the beta-phosphoryl group than to the alpha- or gamma-phosphoryl group was effective in weakening the P-O bond at which the cleavage of ATP catalyzed by most enzymes takes place. Moreover, the orbital coefficient of the frontier electron of P gamma, which is related to the nucleophilic reaction, was shown to increase greatly with increasing interaction between Mg2+ and the beta-phosphoryl group.