Non-deterministic giant waves, denoted as rogue, killer, monster or freak waves, have been reported in many different branches of physics. Their origin is however still unknown: despite the massive numerical and experimental evidence, the ultimate reason for their spontaneous formation has not been identified yet. Here we show that rogue waves in optical fibres actually result from a complex dynamic process very similar to well known mechanisms such as glass transitions and protein folding. We describe how the interaction among optical solitons produces an energy landscape in a highly-dimensional parameter space with multiple quasi-equilibrium points. These configurations have the same statistical distribution of the observed rogue events and are explored during the light dynamics due to soliton collisions, with inelastic mechanisms enhancing the process. Slightly different initial conditions lead to very different dynamics in this complex geometry; a rogue soliton turns out to stem from one particular deep quasi-equilibrium point of the energy landscape in which the system may be transiently trapped during evolution. This explanation will prove fruitful to the wide community interested in freak waves.