We present a new hypothesis to explain the millennial-scale temperature variability recorded in ice cores known as Dansgaard-Oeschger (DO) cycles. We propose that an ice shelf acted in concert with sea ice to set the slow and fast timescales of the DO cycle, respectively. The abrupt warming at the onset of a cycle is caused by the rapid retreat of sea ice after the collapse of an ice shelf. The gradual cooling during the subsequent interstadial phase is determined by the timescale of ice-shelf regrowth. Once the ice shelf reaches a critical size, sea ice expands, driving the climate rapidly back into stadial conditions. The stadial phase ends when warm subsurface waters penetrate beneath the ice shelf and cause it to collapse. This hypothesis explains the full shape of the DO cycle, the duration of the different phases, and the transitions between them and is supported by proxy records in the North Atlantic and Nordic Seas.