Our 13C- and 1H-chemical exchange saturation transfer (CEST) experiments previously revealed a dynamic exchange between partially closed and open conformations of the SAM-II riboswitch in the absence of ligand. Here, all-atom structure-based molecular simulations, with the electrostatic effects of Manning counter-ion condensation and explicit magnesium ions are employed to calculate the folding free energy landscape of the SAM-II riboswitch. We use this analysis to predict that magnesium ions remodel the landscape, shifting the equilibrium away from the extended, partially unfolded state towards a compact, pre-organized conformation that resembles the ligand-bound state. Our CEST and SAXS experiments, at different magnesium ion concentrations, quantitatively confirm our simulation results, demonstrating that magnesium ions induce collapse and pre-organization. Agreement between theory and experiment bolsters microscopic interpretation of our simulations, which shows that triplex formation between helix P2b and loop L1 is highly sensitive to magnesium and plays a key role in pre-organization. Pre-organization of the SAM-II riboswitch allows rapid detection of ligand with high selectivity, which is important for biological function.