Riboswitches are involved in regulating the gene expression in bacteria. They are located within the untranslated regions of bacterial messenger RNA and function as switches by adjusting their shape, depending on the presence or absence of specific ligands. To decipher the fundamental aspects of bacterial gene control, it is therefore important to understand the mechanisms that underlie these conformational switches. To this end, a combination of an experimental binding study, molecular simulations and machine learning has been employed to obtain insights into the conformational changes and structural dynamics of the guanidine-II riboswitch. By exploiting the design of a bivalent ligand, we were able to study ligand binding in the aptamer dimer at the molecular level. Spontaneous ligand-binding events, which are usually difficult to simulate, were observed and the contributing factors are described. These findings were further confirmed by in vivo experiments, where the cooperative binding effects of the bivalent ligands resulted in increased binding affinity compared to the native guanidinium ligand. Beyond ligand binding itself, the simulations revealed a novel, ligand-dependent base-stacking interaction outside of the binding pocket that stabilizes the riboswitch.