A fundamental duty of any efficient memory system is to prevent long-lasting storage of poorly relevant information. However, little is known about dedicated mechanisms that appropriately trigger production of long-term memory (LTM). We examined the role of Drosophila dopaminergic neurons in the control of LTM formation and found that they act as a switch between two exclusive consolidation pathways leading to LTM or anesthesia-resistant memory (ARM). Blockade, after aversive olfactory conditioning, of three pairs of dopaminergic neurons projecting on mushroom bodies, the olfactory memory center, enhanced ARM, whereas their overactivation conversely impaired ARM. Notably, blockade of these neurons during the intertrial intervals of a spaced training precluded LTM formation. Two pairs of these dopaminergic neurons displayed sustained calcium oscillations in naive flies. Oscillations were weakened by ARM-inducing massed training and were enhanced during LTM formation. Our results indicate that oscillations of two pairs of dopaminergic neurons control ARM levels and gate LTM.