There are at least 5 main types of civilzation-ending catastrophes. I'll offer some context and mitigations where I can.
Nuclear War
2 cities destroyed (Hiroshima, Nagasaki), and 15000 warheads remaining. At least ten close calls have occurred.
MAD only works with rational actors. Vote for anti-war politicians, I
guess. I wouldn't bet on first-strike capability. Terrifying and real,
unfortunately. Time frame: Mid-20th century through foreseeable future.
Robotic War
Robotic war directed by evil humans (see drone strikes) or artificial intelligence
(Terminator, The Matrix). While this problem seems much smaller than
nuclear (for the combination, see WarGames), self-replicating robots
could gain numbers quickly. For that matter, viral software
can spread instantly. However humans and A.I. share responsibility,
robotics and software accelerate war. This is the most complex and
open-ended threat. Best bet is serious cyber-security regulations.
Internet-connected devices should receive security patches, have offline
modes, and be refundable or re-programmable at the end of their support
period. This problem is perpetually 5-20 years away, until it's not.
Climate Change
If we can stave off the previous two threats, this will gradually
worsen over the 21st century. Flooding,
drought,
famine, wildfires, and mass migration have already begun. The good news
is that nearly all countries now seem open to greenhouse gas emission
reduction. China is building 100 nuclear power plants and manufacturing
solar panels, so perhaps there is hope. I suggest sanctions on countries
with high per-capita emissions, including our own. Lots of low-hanging
fruit too: Indonesia, for example.
A coal ban seems reasonable, as well as aggressive petroleum taxes to
reflect the true cost to the environment. And stop fishing and raising
cattle on an industrial scale. The impending loss of the Amazon
rainforest will have global consequences.
Pandemic
So far, the most recoverable. I may be underestimating the risk. More risk to regions than civilization.
Can also be combined with war.