Efficient energy use has constrained the evolution of nervous systems. However, it is unresolved whether energy metabolism may resultantly regulate major brain functions. Our observation that Drosophila flies double their sucrose intake at an early stage of long-term memory formation initiated the investigation of how energy metabolism intervenes in this process. Cellular-resolution imaging of energy metabolism reveals a concurrent elevation of energy consumption in neurons of the mushroom body, the fly's major memory centre. Strikingly, upregulation of mushroom body energy flux is both necessary and sufficient to drive long-term memory formation. This effect is triggered by a specific pair of dopaminergic neurons afferent to the mushroom bodies, via the D5-like DAMB dopamine receptor. Hence, dopamine signalling mediates an energy switch in the mushroom body that controls long-term memory encoding. Our data thus point to an instructional role for energy flux in the execution of demanding higher brain functions.