"Good leaders make allowance for the fact that even they can be wrong, and they know when and how to say sorry".
Obama's comments come a day after Trump's comments questioning U.S. intelligence following his summit with Russian President Vladimir Putin earned widespread criticism, and as the Trump administration has been under fire for enacting a "zero-tolerance" stance on migrants crossing the Mexican-U.S. border illegally, which resulted in the separation of almost 3,000 children from their parents.
Obama's barbs were the first he has aimed at Trump since leaving the White House in January 2017.
Obama's speech was attended by many local and national political leaders in Africa.
Politicians using "politics of fear, resentment, retrenchment" were rising "at a pace unimaginable just a few years ago", Mr Obama warned.
"At the current moment we're in, values that we thought were well-established - the importance of human rights, respect for diversity - in many parts of the world those values are under threat", Rhodes told The Associated Press. "History shows how easily people can be convinced to turn on people", said Obama urging people to avoid entrenching social systems of old.
Obama to make rare high-profile speech on Mandela's legacy
Barack Obama said striving towards equality ensures a society can draw on the talents and the energy of all of its people.
Mr. Obama said there are "two different stories, two different narratives" that are battling for the "hearts and minds" of the world.
The former president added: "I am not being alarmist, I am simply stating the facts".
Here are five key points from his Nelson Mandela lecture, made to the world's media and an audience of some 15,000 people in South Africa's main city, Johannesburg.
Trump had been expected by some observers to confront Putin over the issue after the US Department of Justice indicted 12 Russians, accused of hacking the Democrat's emails and computer networks to target Hillary Clinton's presidential campaign. He stepped down in 1999 and died on 5 December 2013, at the age of 95.
It was an implicit rebuke of President Trump's "America First" policies, delivered at a moment when Trump was scolding North Atlantic Treaty Organisation allies for what he saw as inadequate defense spending - something Trump did again last week. "We pride ourselves in only acquiring the very best content and couldn't have asked for a better line-up".
Zulu King Goodwill Zwelithini arrives to hear Obama delivering the 16th Nelson Mandela annual lecture.
Ramaphosa said South Africans celebrated Obama because he shared similar leadership qualities as Mandela and had the same ability to inspire hope and action. After his release, Mandela went on to lead the ANC to victory in the first democratic elections in 1994.