The aim of this study is to obtain a comprehensive experimental and theoretical description of the contributions of Mg2+ ions to the free energy of folding a pseudoknot RNA tertiary structure. A fluorescence method for measuring the effective concentration of Mg2+ in the presence of an RNA was used to study Mg2+-RNA interactions with both folded and partially unfolded forms of an RNA pseudoknot. These data established the excess number of Mg2+ ions accumulated by the folded or partially unfolded RNAs as a function of bulk Mg2+ concentration, from which free energies of Mg2+-RNA interactions were derived. Complementary thermal melting experiments were also used to obtain RNA-folding free energies. These experimental data were compared with the results of calculations based on the nonlinear Poisson-Boltzmann equation, which describes the interaction of "diffuse" (fully hydrated) Mg2+ ions with the different RNA forms. Good agreement between the calculations and experimental data suggests that essentially all of the Mg2+-induced stabilization of the native pseudoknot structure arises from the stronger interaction of diffuse ions with the folded tertiary structure compared to that with a partially unfolded state. It is unlikely that the stability of the RNA depends on dehydrated ions bound to specific sets of RNA ligands in the folded state. The data also suggest that the Mg2+-dependent free energy of folding is sensitive to factors that influence the ensemble of RNA conformations present in the partially unfolded state.