PRETORIA, South Africa – Not much could overshadow the first extended trip to Africa by the first black president of the United States.

But as Barack Obama traveled through the continent this week, he faced an avalanche of questions, anecdotes, even prayers not for his own visit — but for the beloved South African leader Nelson Mandela.

The deteriorating health of the 94-year-old global icon affectionately known here as Madiba has consumed not just South Africa, where Obama spent Saturday, but much of sub-Saharan Africa.

As a result, much of Obama’s trip was transformed into a tribute to Mandela, who led the anti-apartheid movement that coincidentally inspired the political career of a 19-year-old college student and the future president of the United States.

“The struggle here against apartheid, for freedom; Madiba’s moral courage; this country’s historic transition to a free and democratic nation has been a personal inspiration to me,” Obama said Saturday. “It has been an inspiration to the world — and it continues to be. In so many regions that are divided by conflict, sectarian disputes, religious or ethnic wars, to see what happened in South Africa — the power of principle and people standing up for what’s right I think continues to shine as a beacon.”

Obama and Mandela have only met once — Obama keeps a photo in the White House of their brief visit in 2005 when Obama was a freshman senator — but they share a historical link as the first black president in each of their countries.

“The two of you are also 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,” South Africa President Jacob Zama said Saturday.

Obama met privately with Mandela’s two daughters and eight grandchildren at the Nelson Mandela Foundation in Johannesburg and spoke by telephone with Mandela’s wife, Graca Machel, who remained by her husband’s side.

On Sunday, Obama will tour Robben Island, where Mandela was held in a small cell for 18 of his 27 years in prison. Obama will later give the signature speech of the trip in which he will highlight the example Mandela set.

Obama is on the second stop of a weeklong trip to Senegal, South Africa and Tanzania to promote trade, build democracies and inspire youth leaders.