Jeff Bezos’s own space company Blue Origin was also in the running to sign the contract with NASA. However, the US space agency decided to go for Mr Musk’s company, The Washington Post revealed.
The planned spacecraft will eventually send a crewed mission to the Moon in 2024.
Blue Origin, SpaceX and another US technology company, Dynetics, were all given contracts to build a spacecraft for the lunar mission.
However, NASA is reportedly giving SpaceX a $2.9billion deal to build the space technology.
Taking to Twitter on Friday evening, SpaceX confirmed their Starship will send the first humans to the moon since the Apollo missions between 1969 and 1972.
The tweet read: “NASA has selected Starship to land the first astronauts on the lunar surface since the Apollo program!
“We are humbled to help @NASAArtemis usher in a new era of human space exploration.”
The first commercial human lander on the moon hopes to take two American astronauts.
NASA said it plans to make history by having at least one female astronaut in its mission who would be the first woman on the Moon.
Kathy Lueders, NASA’s associate administrator for Human Explorations and Operations Mission Directorate, said in a statement: “With this award, NASA and our partners will complete the first crewed demonstration mission to the surface of the Moon in the 21st century as the agency takes a step forward for women’s equality and long-term deep space exploration.
Mr Bezos recently stepped down as chief executive of his company Amazon to focus on other projects including Blue Origin.
Analysts believe Blue Origin has struggled against its younger rival, SpaceX.
Mr Musk’s space company has become more popular than the two and has found success with its innovative reusable rockets.
The Tesla CEO said the reusable technology will drastically cut down the cost of space travel.
SpaceX’s Starship is intended to evolve into a fully reusable launch and landing system designed for travel to the Moon, Mars and other destinations, according to NASA.