In adulthood, sleep-wake rhythms are one of the most prominent behaviors under circadian control. However, during early life, sleep is spread across the 24-hour day. The mechanism through which sleep rhythms emerge, and the consequent advantage conferred to a juvenile animal, are unknown. In 2nd instar Drosophila larvae (L2), like human infants, sleep is not under circadian control. Here, we identify the precise developmental timepoint when the circadian clock begins to regulate sleep in Drosophila, leading to the emergence of sleep rhythms at the early 3rd instar stage (L3). At this stage, a cellular connection forms between DN1a clock neurons and arousal-promoting Dh44 neurons, bringing arousal under clock control to drive the emergence of circadian sleep. Finally, we demonstrate that L3 but not L2 larvae exhibit long-term memory (LTM) of an aversive cue, and that this LTM depends upon deep sleep generated once sleep rhythms begin. We propose that the developmental emergence of circadian sleep enables more complex cognitive processes, including the onset of enduring memories.