The city on the east coast of South Africa was the only remaining bidder after Edmonton’s bid team withdrew in February for financial reasons.
The Games will begin on July 18 – what would have been the 104th birthday of former South African president Nelson Mandela – and finish on July 30.
It will be the 22nd staging of the event, which is held every four years.
Athletes from more than 50 countries – most of which are former British colonies – compete.
The announcement was made at the Commonwealth Games Federation (CGF) general assembly in Auckland.
“As a movement we stand together to support the very first games on African soil,” said outgoing CGF president, Prince Tunku Imran.
Much of the infrastructure is already in place, with an athletics track to be installed at the Moses Mabhida Stadium, which was built for the 2010 FIFA World Cup.
The Commonwealth Games was last held in 2014 in Glasgow, with Australia’s Gold Coast hosting the 2018 event.