To better understand their survival over the millenia, it is necessary to examine reproductive strategies. Corals, along with numerous other sea creatues, are mass spawners, shedding gametes directly into open water. At the whim of oceanic currents, larval forms are carried far and wide in search of suitable areas for colonization. As old habitats declined, new ones emerged. And larval corals were there and waiting.
Corals have an added advantage.
By secreting massive amounts of limestone, they create additional usable substrate, a type of organic landfill. Thus new and ongoing colonies are literally supported by their ancestors. Millions of them. Coral reefs harbor more species of plants and animals than any other ecosystem on earth, arguably a consequence of having had more time. The wealth of marine life on reefs today is the living legacy of longevity, a lifespan borne of relatively uniform environmental factors in tandem with evolutionary opportunity.