Divalent metal cations are essential cofactors for many enzyme functions. Although Mg(2+) is the native cofactor in many enzymes such as ribonuclease H, its competitor Ca(2+) may also bind to the enzyme but inhibit catalysis. Thus, the competition between Mg(2+) and Ca(2+) for a given metal-binding site in an enzyme and their effects on enzyme activity are of great interest. Most studies have focused on the interactions between Mg(2+) or Ca(2+) and the metal ligands in the first and sometimes second coordination shell. However, no study (to our knowledge) has examined the role of the protein architecture and surrounding aqueous environment on the binding of Mg(2+) vs Ca(2+) to a given protein metal-binding site. In this work, the free energy barriers for the binding of a catalytically essential aspartate to Mg(2+) or Ca(2+) in ribonuclease H from two organisms were computed using umbrella sampling with a classical force field ("classical" model). The corresponding free energy barriers in water were computed using the "classical" model as well as density functional theory combined with a self-consistent reaction field. The results reveal that, relative to water, the protein architecture and coupled protein-water interactions raise the free energy barrier for binding of the catalytically essential aspartate to the native Mg(2+) cofactor more than the respective binding to Ca(2+). They also reveal the physical basis for the different observed binding modes of Mg(2+) and Ca(2+) and highlight limitations of simulations with classical force fields that do not explicitly account for charge transfer and polarization effects.