The tournament for locally-based players is scheduled to take place in January and February 2018.
The decision to move the competition was made at an emergency Caf executive committee meeting in Lagos, Nigeria.
Third candidates, Ethiopia, were not considered, after not providing a letter of guarantee from the country’s government.
The awarding of the tournament to Morocco also benefits Egypt, who were awarded Morocco’s place – now freed up as hosts – after being initially knocked out by their fellow North Africans in qualifying.
It will be Egypt’s first appearance in the competition.
Kenya’s preparations were deemed unsuitable for the biennial 16-team tournament – which runs from 12 January to 4 February 2018 – leading them to be stripped of the hosting rights last month.
Morocco have not hosted a senior continental competition since the 1988 Africa Cup of Nations.