How civilizations thwart extinction in the face of existential crises