JOHANNESBURG -- In his highest profile speech since leaving office, former U.S. President Barack Obama on Tuesday denounced the policies of President Donald Trump without mentioning his name, taking aim at the "politics of fear, resentment, retrenchment," and decrying leaders who are caught lying and "just double down and lie some more."

Obama was cheered by thousands in Johannesburg's Wanderers Stadium as he marked the centenary of Nelson Mandela's birth by urging respect for human rights, the free press and other values he said were under threat.

He rallied people to keep alive the ideals that the anti-apartheid activist worked for as the first black president of South Africa, including democracy, diversity, gender equality and tolerance.

Obama opened by calling today's times "strange and uncertain," adding that "each day's news cycle is bringing more head-spinning and disturbing headlines."

"We see much of the world threatening to return to a more dangerous, more brutal, way of doing business," he said.

A day after Trump met in Helsinki with Russian President Vladimir Putin, Obama criticized "strongman politics."

The "politics of fear, resentment, retrenchment" are on the move "at a pace unimaginable just a few years ago," Obama added.

"Those in power seek to undermine every institution ... that gives democracy meaning," he said.

The first African-American president of the United States spoke up for equality in all forms, adding: "I would have thought we had figured that out by now."

Obama praised the diversity of the World Cup champion French team, and he said that those countries engaging in xenophobia "eventually ... find themselves consumed by civil war."

He noted the "utter loss of shame among political leaders when they're caught in a lie and they just double down and lie some more," warning that the denial of facts -- such as climate change -- could be the undoing of democracy.

But Obama reminded the crowd that "we've been through darker times. We've been through lower valleys."

He closed with a call to action: "I say if people can learn to hate, they can be taught to love."

The crowd gave him a standing ovation in the chilly South African winter.

"Just by standing on the stage honouring Nelson Mandela, Obama is delivering an eloquent rebuke to Trump," said John Stremlau, professor of international relations at Witwatersrand University in Johannesburg.

He called the timing of Obama's speech auspicious -- one day after Trump's summit with Russian President Vladimir Putin -- and said the commitments that defined Mandela's life are "under assault."

"Yesterday, we had Trump and Putin standing together; now we are seeing the opposing team: Obama and Mandela."

This was Obama's first trip to Africa since leaving office in 2017. Earlier this week, he stopped in Kenya, where he visited the rural birthplace of his late father.

Obama's speech noted how Mandela, who was imprisoned for 27 years, kept up his campaign against what appeared to be insurmountable odds to end apartheid, South Africa's harsh system of white minority rule.

Mandela, who was released from prison in 1990 and became president four years later, died in 2013 at the age of 95. He left a powerful legacy of reconciliation and diversity along with a resistance to inequality -- economic and otherwise.

Since leaving the White House, Obama has shied away from public comment on the Trump administration, which has reversed or attacked his notable achievements. The U.S. under Trump has withdrawn from the 2015 Paris climate agreement and the Iran nuclear deal while trying to undercut the Affordable Care Act or "Obamacare."

Obama's speech drew on his great admiration for Mandela, a fellow Nobel Peace Prize winner whom America's first black president saw as a mentor.

When Obama was a U.S. senator, he had his picture taken with Mandela. After Obama became president he sent a copy of the photo to Mandela, who kept it in his office. Obama also made a point of visiting Mandela's prison cell and gave a moving eulogy at Mandela's memorial service in 2013, saying the South African had inspired him.

Many South Africans view Obama as a successor to Mandela because of his groundbreaking role and his support for racial equality in the U.S. and around the world.

Stremlau, who attended the speech, called it "a tough, strong condemnation of Trump and all that he stands for."

"Obama hit out at lying, insecurity and putting down others. Obama said he can't believe it is necessary to once again speak up for equality and human rights," Stremlau said. "He pulled it together in a carefully worded, measured speech, which urged all to live up to Mandela's standards and values."