Barack Obama has chided African leaders who refuse to give up power in the first speech at the African Union headquarters by a US president.
The scolding came in the course of his address on Tuesday in the Ethiopian capital Addis Ababa to the 54-member continental bloc.
"Africa's democratic progress is also at risk when leaders refuse to step aside when their terms end," Obama said. "No one should be president for life."
Obama said he himself was looking forward to handing over to his successor.
"I have to be honest with you: I just don't understand this," he said.
"Under our constitution, I cannot run again. There's still so much I want to get done to keep America moving forward. But the law is the law and no one is above it, not even presidents.
"And, frankly, I'm looking forward to life after being president. It will mean more time with my family, new ways to serve, and more visits to Africa."
Obama singled out Burundi's President Pierre Nkurunziza - whose re-election to a third term provoked weeks of unrest in the small central African nation - as an example of the dangers of trying to stay put.
"When a leader tries to change the rules in the middle of the game just to stay in office, it risks instability and strife, as we've seen in Burundi."
Read more: Obama's parting message to Africa divides Twitter
Obama said clinging to power was "often just a first step down a perilous path".
"If a leader thinks they're the only person who can hold their nation together, then that leader has failed to truly build their country," he said.
He cited Nelson Mandela, the late South African statesman, as an example for the continent.
'Cancer of corruption'
Obama also called on Africa to end "the cancer of corruption" and embrace democracy to ensure continued progress.
He also warned African governments against cracking down on opposition groups and dissent.
He said Ethiopia "cannot unleash the full potential of its people" if it jails journalists and restricts legitimate opposition groups. Ethiopia claims that journalists have been detained because of crimes.
He also urged African leaders to prioritise creating jobs and opportunity for the next generation of young people or risk sacrificing future economic potential to further instability.
Africa's progress will also depend on security and peace, since businesses and wealthy people will not want to invest in unsafe places, Obama said.
"As Africa stands against terror and conflict, I want you to know the United States stands with you," he said, highlighting threats ranging from Somalia's al-Shabab, Boko Haram in Nigeria, fighters in Mali and Tunisia, and the Uganda-led Lord's Resistance Army in Central Africa.
Obama said the US was backing AU military efforts and saluting the "brave African peacekeepers" battling armed groups.
"From Somalia and Nigeria, to Mali and Tunisia, terrorists continue to target innocent civilians," he said.
"Many of these groups claim the banner of religion, but hundreds of millions of African Muslims know that Islam means peace. We must call groups like al-Qaeda, ISIL, al-Shabab and Boko Haram, we must call them what they are - murderers."