Updated

President Barack Obama paid personal respects Saturday to relatives of ailing anti-apartheid icon Nelson Mandela and encouraged leaders in Africa and around the world to follow the former South African president's example of country before self.

"We as leaders occupy these spaces temporarily and we don't get so deluded that we think the fate of our country doesn't depend on how long we stay in office," Obama told reporters shortly before a private, half-hour meeting with Mandela's family.

Obama spoke at a news conference with South African President Jacob Zuma in the midst of a weeklong tour of the continent that also included stops in Senegal and Tanzania, two nations where there has been progress toward democratic governance. But many other nations on the African continent are embroiled in religious, sectarian and other conflicts.

Obama decided to avoid stopping in his father's home nation of Kenya because of international disputes there. The International Criminal Court is prosecuting Kenyan President Uhuru Kenyatta for crimes against humanity, including murder, deportation, rape, persecution and inhumane acts allegedly committed by his supporters in the violent aftermath of Kenya's 2007 elections.

"The timing was not right for me as the president of the United States to be visiting Kenya when those issues are still being worked on, and hopefully at some point resolved," Obama said. He noted he's visited Kenya several times previously and expects he will in the future as well.

Obama and Zuma appeared at the Union Buildings that house government offices and were the site of Mandela's 1994 inauguration as the country's first black president after 27 years behind bars for his activism.

The 94-year-old Mandela has been in a nearby hospital for three weeks after being admitted with a lung infection. Zuma told reporters that Mandela is in critical but stable condition. The White House said that in accordance with the family's wishes, Obama was not planning to see the man he has called a personal hero and revered Saturday as "one of the greatest people in history."

But Obama did meet with two of Mandela's daughters and eight of his grandchildren at the Nelson Mandela Centre of Memory, part of the former president's foundation. Obama said he told the family he hopes Mandela draws comfort from the time he's spending with loved ones.

"I also reaffirmed the profound impact that his legacy has had in building a free South Africa, and in inspiring people around the world -- including me," Obama said in a statement after the visit. "That's a legacy that we must all honor in our own lives."

Obama also spoke by telephone with Graca Machel, Mandela's wife, while she stayed at his bedside in the hospital. Machel said she drew strength from the call and that Obama added a characteristic "touch of personal warmth."

"I am humbled by their comfort and messages of strength and inspiration, which I have already conveyed" to Mandela, she said.

Zuma told Obama he and Mandela are "bound by history as the first black presidents of your respective countries."

"Thus, you both carry the dreams of millions of people in Africa and in the diaspora who were previously oppressed," Zuma said at their news conference, reading from a prepared statement.

On other topics, Obama declined to commit to supporting South Africa's bid for a permanent seat on the United Nations Security Council. He said the U.N.'s structure needs to be updated and it would be "odd" for an expanded Security Council not to have African representation.

"How we do that and what fashion is complicated, it's difficult and it involves all kinds of politics," Obama said.

"Everybody wants a seat at the table, but when it comes time to step up and show responsibility, sometimes people want to be free-riders," Obama said, adding he wasn't referring to South Africa specifically.

Obama also said he wants to boost trade with Africa and plans to renegotiate an African trade pact to improve it for American businesses. He said he welcomes competition from other nations who have been aggressive in pursuing commercial opportunities in Africa, including China.

"I don't feel threatened by it. I think it's a good thing," he said. He added: "Our only advice is make sure it's a good deal for Africa." He said that includes making sure foreign investment employs Africans and doesn't tolerate corruption or take its natural resources without compensation for Africans.

Obama also paid tribute to South Africa's fight against apartheid by visiting the Soweto area Saturday afternoon for a town hall with students at the University of Johannesburg. At least 176 young people were killed in Soweto township 27 years ago this month during a youth protest against the apartheid regime's ban against teaching local Bantu languages. The Soweto Uprising catalyzed international support against apartheid, and June is now recognized as Youth Month in South Africa.

Obama announced the formation of the Washington Fellowship for Young African Leaders, which beginning next year will bring more than 500 25- to 35-year-olds to the United States to train them for civic and business leadership. The fellows will spend six weeks on U.S. campuses for instruction, mentoring and internships, as well as attend a summit with Obama.

The White House says fellowship partners will provide career options when they return home, and the fellows will become part of an alumni network that will offer future opportunities. Obama told his audience -- including people from Kenya, Nigeria, and Uganda participating by videoconference -- that the continent has a brighter future. Invoking a refrain from his own presidential campaign, Obama praised young Africans for having a "yes we can attitude."

About 150 protesters from a range of trade unions and civil society groups demonstrated outside the university ahead of Obama's arrival, but police fired warning shots and cleared the streets by the time of the town hall. Some had dressed in orange coveralls to protest the Guantanamo Bay prison and other held signs depicting Obama with an Adolf Hitler moustache.

"People died in Libya. People are still dying in Syria," said 54-year-old Ramasimong Tsokolibane. "In Egypt, in Afghanistan in Pakistan drones are still killing people. So that's why we are calling him a Hitler. He's a killer."

Obama wraps up his South Africa stay Sunday, when he plans to give a sweeping speech on U.S.-Africa policy at the University of Cape Town and take his family to Robben Island to tour the prison where Mandela spent 18 of his 27 years behind bars.

Obama has visited the island before, but said it's a particular privilege to bring his daughters back to learn its lessons.