RNA molecules can fold into noncanonical structures such as the four-stranded structures known as G-quadruplexes. G-quadruplexes in the transcriptome have recently emerged as relevant regulatory elements of gene expression. Conformational transitions in RNA molecules offer an important way to regulate their biological functions. Here we report on the competition between a canonical hairpin structure and a G-quadruplex structure within an RNA molecule. We show that the conformational preference strongly depends on the relative amounts of mono- and divalent metal ions present in solution. In our system, the G-quadruplex, whose formation is not predicted by available predictive RNA folding programs, is the major conformer at physiologically relevant K(+) and Mg(2+) concentrations. Furthermore, we show that a synthetic small molecule can displace the structural dynamic equilibrium in favor of the hairpin conformer. This work highlights a new and important level of complexity in RNA folding that could be relevant to the biological functions and targeting of RNAs comprising G-quadruplex motifs.