There are lots of dangers threatening the Earth and humanity but those listed below are the most serious.
Danger #1: Meteorite Impact
This is what would happen if a huge meteorite of more than 10 km of diameter collided with the Earth.
Danger #2: Nuclear War
Although much less probable than during the Cold War and much exaggerated as a scenario, a nuclear war could still be a threat to humanity in the near future.
Danger #3: Global warming and other natural catastrophes
Unlike the two previous threats to humanity, global warming is not exaggerated at all. It is a serious threat to the Earth and its consequences can be fatal to the human race.
Danger #4: Overpopulation
This is another serious danger threatening the Earth and humanity as a whole. The human population is constantly rising at an exponential rate. The time when the Earth wouldn’t be able to support us anymore is quite near.
Therefore the importance of space colonization is obvious. If such catastrophes ever were to happen, at least a part of humanity would survive in the space colonies. Space colonization is also a direct long-term solution to the overpopulation problem and thus also, in a certain point, to the global warming problem.