Asteroids are left over material from the formation of the solar system which primarily orbit around the Sun between Mars and Jupiter. Occasionally due to perturbations in the orbit due to gravity influences an asteroid will swing into an orbit close to that of the earth. Such an asteroid hit the earth 66 million years ago and new evidence has been recently recovered that demonstrate this collision was responsible for the extinction of the dinosaurs that allowed mammals to dominate.
The danger of a modern day asteroid collision (such as the one that killed the dinosaurs) is still very much a possibility and despite our new radar tracking systems we are still surprised by small* asteroids that sneak up on earth without being detected until the last (figurative) minute.
Unfortunately humankind does not have the technology in place to deflect an asteroid should we detect one in time. Despite what one has seen in movies a nuclear warhead would not be enough but given enough warning it would be possible to gently nudge an errant asteroid into an orbit which would miss the earth.
* Too small to easily detect, but big enough to cause major upheaval