Animals must set behavioural priority in a context-dependent manner and switch from one behaviour to another at the appropriate moment1-3. Here we probe the molecular and neuronal mechanisms that orchestrate the transition from feeding to courtship in Drosophila melanogaster. We find that feeding is prioritized over courtship in starved males, and the consumption of protein-rich food rapidly reverses this order within a few minutes. At the molecular level, a gut-derived, nutrient-specific neuropeptide hormone-Diuretic hormone 31 (Dh31)-propels a switch from feeding to courtship. We further address the underlying kinetics with calcium imaging experiments. Amino acids from food acutely activate Dh31+ enteroendocrine cells in the gut, increasing Dh31 levels in the circulation. In addition, three-photon functional imaging of intact flies shows that optogenetic stimulation of Dh31+ enteroendocrine cells rapidly excites a subset of brain neurons that express Dh31 receptor (Dh31R). Gut-derived Dh31 excites the brain neurons through the circulatory system within a few minutes, in line with the speed of the feeding-courtship behavioural switch. At the circuit level, there are two distinct populations of Dh31R+ neurons in the brain, with one population inhibiting feeding through allatostatin-C and the other promoting courtship through corazonin. Together, our findings illustrate a mechanism by which the consumption of protein-rich food triggers the release of a gut hormone, which in turn prioritizes courtship over feeding through two parallel pathways.