Mosquito-borne flaviviruses including dengue, Zika, yellow fever, and regional encephalitis produce a large amount of short subgenomic flaviviral RNAs during infection. A segment of these RNAs named as xrRNA1 features a multi-pseudoknot (PK)associated structure, which resists the host cell enzyme (XRN1) from degrading the viral RNA. We investigate how this long-range RNA PK folds in the presence of counterions, specifically in a mix of monovalent (K + ) and divalent (Mg 2+ ) salts at physiological concentrations. In this study, we use extensive explicit solvent molecular dynamics (MD) simulations to characterize the RNA ion environment of the folded RNA conformation, as determined by the crystal structure. This allowed us to identify the precise locations of various coordinated RNA−Mg 2+ interactions, including inner-sphere/chelated and outer-sphere coordinated Mg 2+ . Given that RNA folding involves large-scale conformational changes, making it challenging to explore through classical MD simulations, we investigate the folding mechanism of xrRNA1 using an allatom structure-based RNA model with a hybrid implicit−explicit treatment of the ion environment via the dynamic counterion condensation model, both with and without physiological Mg 2+ concentration. The study reveals potential folding pathways for this xrRNA1, which is consistent with the results obtained from optical tweezer experiments. The equilibrium and free energy simulations both capture a dynamic equilibrium between the ring-open and ring-close states of the RNA, driven by a long-range PK interaction. Free energy calculations reveal that with the addition of Mg 2+ ions, the equilibrium shifts more toward the ring-close state. A detailed analysis of the free energy pathways and ion-mediated contact probability map highlights the critical role of Mg 2+ in bridging G50 and A33. This Mg 2+ -mediated connection helps form the long-range PK which in turn controls the transition between the ring-open and ring-close states. The study underscores the critical role of Mg 2+ in the RNA folding transition, highlighting specific locations of Mg 2+ contributing to the stabilization of long-range PK connections likely to enhance the robustness of Xrn1 resistance of flaviviral xrRNAs.