Talk about a close shave!

A craggy, 1,300-foot wide bit of space rock missed Earth tonight in the closest encounter by such a massive space rock in more than three decades.

Countless asteroids, gravity wells and other celestial bodies had shaped its course that could have turned this near miss into a disaster, said Ron Dantowitz, director of the Clay Center Observatory in Brookline, Mass.

"Everything shapes its course," Datowitz told FoxNews.com, even the Earth and moon that asteroid 2005 YU55 breezed past at 6:28 p.m. EST Tuesday, Nov. 8. At that point, the space rock was traveling at about 29,000 mph ... a whopping 8 miles per second.

The asteroid has travelled light years to reach us, on a trajectory affected by planets, asteroids, space dust and more. Tonight it was a mere 201,700 miles from Earth -- closer than the moon at one point.

What if the tug of gravity from a planet in a galaxy far, far away had been slightly stronger? What if the course of asteroid 2005 YU55 had been altered by a tiny amount, a few micrometers -- micrometers that added up over the course of millions of light years?

Indeed, even the effect of light is enough to alter the path of an asteroid.

"The … reflection and ... re-emission of sunlight from an asteroid's surface acts as a propulsion engine," wrote Finnish researcher Mikko Kaasalainen of the University of Helsinki in a 2007 article in Nature magazine.

The force he described is called the 'Yarkovsky-O'Keefe- Radzievskii-Paddack effect' or YORP for short. As an asteroid turns, sunlight slightly warms each side, which causes it to spin away and lose this heat to the chill of space. And that tiny spin adds up, over the course of trillions of miles.

“It’s a small effect on human time scales,” Jean-Luc Margot, a professor of astronomy at Cornell University told the New York Times at the time. “It’s an enormous effect on geological time scales.”

Solar energy aside, NASA relies on a physical model of the solar system that takes into account the gravitational influence of the sun, moon, and other planets, as well as the three largest asteroids to predict the path of racing asteroids.

Asteroid 2005 YU55 travels an elliptical path, of course, meaning it passes the Earth, Venus and Mars regularly -- zooming over our oblivious heads many times already, he said.

"The scary thing: This thing has been past the Earth several times and we never even noticed it," Datowitz warned.

He pointed out that an asteroid impact is ultimately inevitable. It's happened before, and it will happen again.

"It's literally a matter of time," Datowitz told FoxNews.com. "The bad news, the last one hit about 60 million years ago, give or take." There's another one coming, in other words, and we're almost overdue for it.

"It's a reminder that we need to pay attention to the things out in space," he said.