Every object in the universe, even something as small as a pebble, has gravity. You can't feel a pebble's gravity because its mass is so small, but it's still there, tugging away on anything that comes close. The close part is important because gravity is also related to the distance separating two objects. The closer they are, the greater the gravitational attraction.
A spacecraft zipping through the solar system obeys the same principles, exerting a gravitational pull directly proportional to its mass and inversely proportional to the distance between it and another object. Now, compared to an asteroid, which might have the mass of Mount Everest, a spacecraft is pretty puny, but its gravity can still make things happen. In fact, if you place an unmanned probe in a close orbit around an asteroid, it will pull ever so slightly on the rock. Over a period of 15 years or more, this almost infinitesimal tug could deflect the asteroid's orbit just enough to protect Earth from a nasty blow [source: BBC News].
Astronomers refer to this as a gravitational tractor and think it's a viable solution -- as long as they know about a potential collision years in advance. Early detection is just as critical to the next idea on the list.