Many seemingly different soft materials—such as soap foams, mayonnaise, toothpaste and living cells—display strikingly similar viscoelastic behaviour. A fundamental physical understanding of such soft glassy rheology and how it can manifest in such diverse materials, however, remains unknown. Here, by using a model soap foam consisting of compressible spherical bubbles, whose sizes slowly evolve and whose collective motion is simply dictated by energy minimization, we study the foam’s dynamics as it corresponds to downhill motion on an energy landscape function spanning a high-dimensional configuration space. We find that these downhill paths, when viewed in this configuration space, are, surprisingly, fractal. The complex behaviour of our model, including power-law rheology and non-diffusive bubble motion and avalanches, stems directly from the fractal dimension and energy function of these paths. Our results suggest that ubiquitous soft glassy rheology may be a consequence of emergent fractal geometry in the energy landscapes of many complex fluids.