A NASA spaceship hit an asteroid 7 million miles away in order to prevent it from hitting us.

10 months after launching from California, the Double Asteroid Redirection Test hit its target, the space rock Dimorphos.

The director of NASA's planetary science division said that they could potentially protect themselves from a dangerous asteroid impact.

The last image was taken by the camera on the DART.

Close-up image of asteroid moon
The penultimate and last complete image of asteroid moonlet Dimorphos, taken 2 seconds before impact. The image shows a patch of the asteroid that is 31 meters across. (NASA/Johns Hopkins APL)

The big brother of Dimorphos is called Didymos, and it's about half a mile in length. Around an hour before the collision, the moonlet appeared as a small light.

The craggy, boulder-dotted surface finally came into view in the last few minutes as DART raced towards it.

Black and white image showing two small rocks in space
Asteroid Didymos (top left) and its moonlet, Dimorphos, about 2.5 minutes before the impact of NASA's DART spacecraft. (NASA/John Hopkins APL)

As the screen froze on a final image, NASA scientists and engineers erupted in applause.

The asteroids don't pose a threat to our planet because they loop the Sun every two years.

The experiment is important to carry out before a need is found.

The time it takes to encircle Didymos is currently 11 hours and 55 minutes.

Asteroid Dimorphos in space
Asteroid moonlet Dimorphos as seen by the DART spacecraft 11 seconds before impact. This image was the last to contain all of Dimorphos in the field of view. (NASA/Johns Hopkins APL)

Ground telescopes, which can't see the asteroid directly but can detect a shift in patterns of light coming from it, should give a definitive orbital period in the coming days and weeks.

In films such as Armageddon and Don't Look Up, the proof-of-concept has made a reality of what has been attempted before.

The final image was taken by DART.

Incomplete image of asteroid moon Dimorphos
DART's final look at the asteroid moonlet Dimorphos captured 1 second before impact. Impact occurred during transmission of the image to Earth, resulting in a partial picture. (NASA/Johns Hopkins APL)

Astronomy community abuzz

LICIACube, which separated from DART a few weeks ago, was expected to make a close pass of the site to take pictures of the collision and the ejected rock.

The pictures will be sent back in a few weeks.

An array of telescopes, both on Earth and in space, can be used to look for a cloud of dust.

More than three dozen ground telescopes are participating in the mission.

Christina Thomas said it was exciting to have lost count.

A full picture of what the system looks like will be revealed when a European Space Agency mission four years down the line called Hera arrives to survey Dimorphos' surface.

'Earthlings can sleep better'

None of the billions of asteroids and comets in our solar system are likely to be dangerous in the next hundred years.

Wait a long time and it will happen.

The mass extinction of the dinosaurs along with 75 percent of all species was caused by a six mile wide asteroid hitting Earth 66 million years ago.

An asteroid the size of Dimorphos would only cause a regional impact, such as devastating a city, with greater force than any nuclear bomb in history.

It's not yet known if the asteroid is solid rock or a pile of boulders bound by mutual gravity.

NASA would have another chance in two years' time if it had missed.

It marks the beginning of a world that can defend itself from a future threat.

Elena Adams thinks Earthlings can sleep better.

Agence France- Presse.