In 1842 Charles Darwin claimed that vertical growth on a subsiding foundation caused fringing reefs to transform into barrier reefs then atolls. Yet historically no transition between reef types has been discovered and they are widely considered to develop independently from antecedent foundations during glacio-eustatic sea-level rise. Here we reconstruct reef development from cores recovered by IODP Expedition 310 to Tahiti, and show that a fringing reef retreated upslope during postglacial sea-level rise and transformed into a barrier reef when it encountered a Pleistocene reef-flat platform. The reef became stranded on the platform edge, creating a lagoon that isolated it from coastal sediment and facilitated a switch to a faster-growing coral assemblage dominated by acroporids. The switch increased the reef's accretion rate, allowing it to keep pace with rising sea level, and transform into a barrier reef. This retreat mechanism not only links Darwin's reef types, but explains the re-occupation of reefs during Pleistocene glacio-eustacy.