Former US president Barack Obama urged people around the world to respect human rights and other values under threat in an address marking the 100th anniversary of anti-apartheid leader Nelson Mandela’s birth.

In his highest-profile speech since leaving office, Mr Obama’s speech in South Africa countered many of Donald Trump’s policies, although he steered clear of direct criticism.

Mr Obama rallied people to keep alive the ideas that Mandela worked for including democracy, diversity and good education for all.

Mr Obama opened by describing the times as “strange and uncertain”, adding that “each day’s news cycle is bringing more head-spinning and disturbing headlines”.

These days “we see much of the world threatening to return to a more dangerous, more brutal, way of doing business”, Mr Obama said.

His words were met with cheers by a crowd of about 14,000 people gathered at a cricket stadium in Johannesburg for the speech, which was streamed online.

“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.

South Africa Obama Mandela Speech
Barack Obama, left, delivers his speech (Themba Hadebe/AP)

He called the timing auspicious as the commitments that defined Mandela’s life are “under assault” in the US and elsewhere.

“Yesterday we had Trump and (Vladimir) Putin standing together, now we are seeing the opposing team: Obama and Mandela.”

Mr Obama is making his first visit to Africa since leaving office in early 2017 and stopped earlier this week in Kenya, where he visited the rural birthplace of his late father.

Mr Obama’s speech highlighted how the Nobel Peace Prize winner, 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.

South Africa Obama Mandela Speech
People gather below a giant banner of the late Nelson Mandela (Themba Hadebe/AP)

Mandela, who was released from prison in 1990 and became South Africa’s first black president four years later, died in 2013, leaving a powerful legacy of reconciliation and diversity along with a resistance to inequality, economic and otherwise.

Mr Obama has shied away from public comment on Mr Trump, whose administration has reversed or attacked notable achievements of his predecessor.

The US under Mr Trump has withdrawn from the 2015 Paris climate agreement and the Iran nuclear deal while trying to undercut the Affordable Care Act or Obamacare.

Instead of commenting on politics, Mr Obama’s speech was drawing on broader themes and his admiration for Mandela, whom America’s first black president saw as a mentor.

Warming to his theme, Mr Obama said politicians pushing “politics of fear, resentment, retrenchment” are on the move “at a pace unimaginable just a few years ago”.

He said:  “Those in power seek to undermine every institution … that gives democracy meaning.”

Attacking “strongman politics”, he added: “I am not being alarmist, I am simply stating the facts. Look around.”