The space agency live-streamed the unmanned probe's approach as it grew closer and closer to the asteroid.
In images transmitted to Earth by the spacecraft's camera, the asteroid Dimorphos first became visible as a bright dot about an hour before impact, then grew in size and was eventually visible with surface detail and shading - until the camera was destroyed on impact and the image displayed a red glitch.
Cheers then broke out in Nasa's control centre, with the team clapping and hugging each other.
Until just before impact, it was uncertain whether the spacecraft, travelling at a speed of about 6.6 kilometres per second and on autopilot for the last few minutes, would actually hit the asteroid.
NASA scientist Lori Glaze said the real scientific work begins after the impact. Researchers must now investigate whether Dimorphos' roughly 12-hour orbit has changed as a result of the probe's impact and if so, to what extent.
The mission is designed to ensure the asteroid poses no danger even after the probe hits it. NASA hopes to gain insights from the mission into how Earth could be protected from a near-Earth object (NEO) – meaning an asteroid or comet – that could approach our orbit.
NASA established the Planetary Defence Coordination Office (PDCO) in 2016 to provide early detection of threats from NEOs of a size large enough - starting at about 30 to 50 metres - to damage Earth's surface and to track their paths.
Astronomers are not currently aware of NEOs that could threaten Earth, but an asteroid impact some 66 million years ago that left a huge crater in Mexico's Yucatan Peninsula is believed by many to have led to the extinction of the dinosaurs.