South Africans have joined former US president Barack Obama in marking the centennial of anti-apartheid leader Nelson Mandela’s birth with acts of charity in a country still struggling with deep economic inequality 24 years after the end of white minority rule.

Mr Obama met young leaders from around Africa to mark the anniversary, a day after he delivered a spirited speech in Johannesburg about Mr Mandela’s legacy of tolerance and criticised US president Donald Trump and his policies without mentioning him by name.

The former president received a standing ovation for his address, his highest-profile speech since he left office.

Barack Obama
Mr Obama told people to find a way not to sell their souls (AP)

“Most people think of Mandela as an older man with hair like mine,” the 56-year-old Mr Obama said to laughter from his audience.

“But he started as a very young man, at your age, trying to liberate this country.”

He urged African leaders to pursue change at home and emphasised the impact they can have as the continent’s population is the fastest-growing in the world.

“How big are your ambitions?” he asked.

Mr Obama also spoke out against the corruption and conflict that slow down change, mentioning as one example the current deadly tensions in Cameroon, which faces an Anglophone separatist movement and the threat from Boko Haram extremists based in neighbouring Nigeria.

“Find a way where you’re not selling your soul,” Mr Obama said, as he urged more political and community involvement, especially from women.

Mr Obama and the Soweto Gospel Choir
Mr Obama listens to members of the Soweto Gospel Choir (AP)

South Africans and others around the world are marking the July 18 100th birthday of Mr Mandela with clinic openings, blanket handouts and other charitable acts.

After 27 years in prison in South Africa, Mr Mandela was released in 1990 and became the country’s first black president four years later. He died in 2013 at the age of 95.

Events have been planned throughout the year for the 100th anniversary of his birth, including a large concert in December in South Africa that will be headlined by Beyonce and Jay-Z and hosted by Oprah Winfrey and others.

Crowds hail Nelson Mandela
People around the world are marking 100 years since Mr Mandela’s birth (AP)

In a video message, former South African archbishop Desmond Tutu said Mr Mandela reflected the best of humanity.

Archbishop Tutu, who won the Nobel Peace Prize for his efforts to end apartheid and reconcile South Africans, said: “Good leaders make allowance for the fact that even they can be wrong, and they know when and how to say sorry. Madiba had this quality in abundance.”

United Nations Secretary-General Antonio Guterres in a separate statement called Mr Mandela a towering advocate for equality and justice.

He said: “Nelson Mandela was held captive for many years. But he never became a prisoner of his past.

“Rarely has one person in history done so much to stir people’s dreams and move them to action.”