The 2026 World Cup will be jointly held in the US, Canada, and Mexico following a vote by FIFA's member associations.
The joint bid, known as the United bid, received 134 votes to Morocco's 65.
It will be only the second time there have been joint hosts for the World Cup, after Japan and South Korea hosted the tournament in 2002.
The United bid has long been regarded as the favorite to win, but questions were raised in April when President Donald Trump appeared to warn countries not to vote against the US, despite FIFA rules stipulating against political influence.
Trump tweeted his congratulations to the bid team after the result was announced.
The electronic vote, made at the FIFA Congress in Moscow on the eve of the 2018 World Cup starting in Russia, was public, in part to draw a line under the heavily criticized votes that led to Russia and Qatar, which will host in 2022, winning.
The United bid team said they would generate profits of $11 billion for FIFA, compared with $5 billion from Morocco.
The US will host 60 of the 80 games, with Canada and Mexico sharing the remainder, but every game from the quarter-finals onwards will take place in the US.
The United bid was based around all the stadiums and infrastructure already being in place, while Morocco said it would need to build almost all its stadiums over the next eight years.
Mexico has twice hosted the World Cup, in 1970 and 1986, while the US hosted in 1994. This is the fifth time Morocco has bid unsuccessfully to hold the tournament. It would have become the second African country after South Africa in 2010 to host the World Cup.