The choice of Mandela and South Africa are freighted with symbolism for Mr. Obama at a time when his political legacy is being dismantled by his successor, President Trump, who crudely disparaged African countries and complained about laws that would protect immigrants from those places.
“It gives him an opportunity to lift up a message of tolerance, inclusivity and democracy at a time when there are obviously challenges to Mandela’s legacy around the world,” said Benjamin J. Rhodes, a former speechwriter for Mr. Obama who still advises him.
“Mandela,” he added, “endured far darker times than anything we’re enduring today.”
Mr. Obama does not plan to take on Mr. Trump directly, in keeping with his practice of not publicly criticizing his successor. But Mr. Rhodes said he would not shrink from confronting the divisive issues raised by the Trump presidency.
“There’s an enhanced sense of tribalism in the world,” he said. “Our unifying theory is that the best way to promote inclusive and democratic societies is by empowering young people in civil society.”
Mr. Obama, he said, views this as the most important speech he has given since leaving the White House, one that will set the tone for his post-presidency. Mandela was a beacon to Mr. Obama, inspiring what he once said was his first “act of political activism” — a speech he gave as a student at Occidental College for the anti-apartheid movement.
He labored over his eulogy to Mandela, rewriting Mr. Rhodes’s draft from top to bottom in longhand — something he had done only once before, with his acceptance speech for the Nobel Peace Prize. Mr. Rhodes said he expected the former president, with more time on his hands now, to write this speech himself.
Mr. Obama and his wife, Michelle, remained in Washington after he left office, so their younger daughter, Sasha, could finish school. But they have kept a low profile in the capital. Much of Mr. Obama’s time is spent working on his presidential memoir. He has largely steered clear of domestic politics, though aides said they expected him to return to the campaign trail as the midterm elections draw closer.
Overseas, however, Mr. Obama has cut a wider swath. He has visited 16 countries for speeches or meetings, drawing crowds and V.I.P. treatment everywhere he goes. In Beijing, Mr. Xi invited him to a private dinner to sound him out about political developments in the United States.
The Obama Foundation’s emphasis on developing young people, Mr. Rhodes said, is consciously different than the focus of other foundations, like those of Bill Clinton or Bill and Melinda Gates, which tend to concentrate on solving specific problems. He said it drew on Mr. Obama’s roots as a community organizer in Chicago.
“When I was in my last year in office, part of what I asked myself is, ‘What would be the most important contribution I could make?’” Mr. Obama said during a recent round table with young people in Singapore. “What I really felt most strongly about was, ‘How do we develop the next generation of leaders?’”
The Obama Foundation’s Africa program is a yearlong initiative that aims to train people for roles in government, civil society and the private sector. The 200 participants were chosen from an applicant pool of nearly 10,000, said Bernadette Meehan, a former diplomat who oversees the program as chief international officer of the foundation.
Mr. Obama plans to recruit veterans of his administration and big-name friends to speak to the young people in Johannesburg. He will hold a town-hall-style meeting with them at the end, something he made a practice of doing during his trips as president.
For his former aides and supporters, looking back on those sessions can be bittersweet. During a visit to Laos in September 2016, Mr. Obama used one of these meetings, part of a program called the Young Southeast Asian Leaders Initiative, to promote the Trans-Pacific Partnership, a trade agreement that was intended to include the United States and other Pacific Rim countries.
A young Vietnamese man asked him about the failure of Congress to ratify the pact, and whether the prospects for the agreement would be better or worse under a new president.
“I believe it will be ratified because it’s the right thing to do,” Mr. Obama replied. “We’re in a political season now, and it’s always difficult to get things done. Congress isn’t doing much right now; they’re all going home and talking to constituents, trying to get re-elected. After the election, people can refocus attention on why this is so important.”
As it turned out, of course, Mr. Trump was elected, and he pulled the United States out of the trade agreement in his first week in office.