Morocco has been readmitted as a member of the African Union (AU) after months of intense lobbying.
Morocco left the organisation in 1984, after it recognised the independence of Western Sahara, regarded by Morocco as part of its historic territory.
It was the only country in Africa that was not a member of the continental body.
AU leaders also voted for Chadian Foreign Minister Moussa Faki Mahamat to be the next head of the AU commission.
Mr Faki Mahamat beat Kenya's top diplomat Amina Mohamed.
The race is usually settled behind the scenes before the vote but this went to seven rounds of voting.
Outgoing commissioner, South Africa's Nkosazana Dlamini-Zuma, stayed in the job an extra six months after leaders failed to agree a candidate in July.
Mr Faki garnered 39 votes in a hotly contested election at the ongoing heads of state summit in the city.
While campaigning for the job, he said he dreamt of an Africa where the "sound of guns would be drowned out by cultural songs and rumbling factories" and pledged to streamline the bureaucratic AU during his four-year term in office.
Analysts say he was considered an outsider but being at the forefront of the fight against Islamist militants in Nigeria, Mali and the Sahel may have worked in his favour.
Western Sahara is the last African case on the United Nations decolonisation committee.
A referendum was promised in 1991 but never carried out due to wrangling over who is eligible to vote.
BBC World Service Africa editor James Copnall says the issue is likely to remain contentious despite Morocco's readmission to the AU.
Western Sahara row
- 1975-76: Morocco seizes two-thirds of Western Sahara after colonial power Spain withdraws.
- 1975-76: Polisario Front declares the Saharan Arab Democratic Republic (SADR), with a government-in-exile in Algeria. Thousands of Sahrawi refugees flee to western Algeria to set up camps.
- 1984: Morocco leaves the Organisation of African Unity (which later became the African Union) in protest at the SADR's admission to the body.
- 1991: UN-monitored ceasefire begins in Western Sahara, but the territory's status remains undecided and ceasefire violations are reported. The following decade sees much wrangling over a proposed referendum on the future of the territory but the deadlock is not broken.
- March 2016: Morocco threatens to pull its soldiers out of UN global peacekeeping missions in Western Sahara, after UN Secretary-General Ban Ki-moon uses the term "occupation" when referring to the territory.
- May 2016: Long-time Polisario Front leader Mohamed Abdelaziz dies aged 68