The last glacial interval experienced abrupt climatic changes called Dansgaard-Oeschger (DO) events. These events manifest themselves as rapid increases followed by slow decreases of oxygen isotope ratios in Greenland ice core records. Despite promising advances, a comprehensive theory of the DO cycles, with their repeated ups and downs of isotope ratios, is still lacking. Here, based on earlier hypotheses, we introduce a dynamical model that explains the DO variability by rapid retreat and slow regrowth of thick ice shelves and thin sea ice in conjunction with changing subsurface water temperatures due to insulation by the ice cover. Our model successfully reproduces observed features of the records, such as the sawtooth shape of the DO cycles, waiting times between DO events across the last glacial, and the shifted antiphase relationship between Greenland and Antarctic ice cores. Our results show that these features can be obtained via internal feedbacks alone. Warming subsurface waters could have also contributed to the triggering of Heinrich events. Our model thus offers a unified framework for explaining major features of multimillennial climate variability during glacial intervals.