The contract, worth $2.9 billion, involves the prototype Starship spacecraft that is being tested at SpaceX's south Texas facility.
"Today I'm very excited, and we are all very excited to announce that we have awarded SpaceX to continue the development of our integrated human landing system," said Lisa Watson-Morgan, NASA's Human Landing System program manager.
SpaceX beats out Jeff Bezos' Blue Origin and defense contractor Dynetics to be the sole provider for the system, a surprising break from the past when NASA has chosen multiple companies in case one fails.
Industry analysts said the decision underscores the company, founded by Musk in 2002 with the goal of colonizing Mars, as NASA's most trusted private sector partner.
Last year, SpaceX became the first private firm to successfully send a crew to the International Space Station, restoring American capacity to accomplish the feat for the first time since the Shuttle program ended.
For its Moon lander bid, SpaceX put forward its reusable Starship spacecraft, which is designed to carry large crews and cargo for deep space voyages, and land upright both on Earth and other celestial bodies.
Prototypes of the vessel are currently being put through their paces at the company's south Texas facility, though all four versions that have so far attempted test flights have exploded.
Under the Artemis program to return humans to the Moon, NASA wants to use the Space Launch System rocket to launch four astronauts on board an Orion crew capsule, which will then dock with a lunar space station called Gateway.
Starship will be waiting to receive two crew members for the final leg of the journey to the surface of the Moon.
The idea is for Gateway to be the go-between but for the initial mission Orion might dock directly with Starship, Watson-Morgan said.
The astronauts would then spend a week on the Moon before boarding Starship to return to lunar orbit, then take Orion back to Earth.
Separately, SpaceX has plans to combine the Starship spaceship with its own Super Heavy rocket, to make a combined vessel that will tower 394 feet (120 meters) tall and be the most powerful launch vehicle ever deployed.
Humanity last stepped foot on the Moon in 1972 during the Apollo program.
NASA wants to go back and establish a sustainable presence, complete with a lunar space station, in order to test new technologies that will pave the way for a crewed mission to Mars.
In 2019, then-Vice President Mike Pence challenged NASA to land the first woman and the next man on the Moon by 2024, but it's likely that timeline will be relaxed under President Joe Biden.
Another change under the current administration is its stated goal of placing the first person of color on the Moon under the Artemis program.