The US President meets two of Mr Mandela’s daughters, several of his grandchildren and offers comfort to his wife on the phone.
Barack Obama has told Nelson Mandela’s wife he hopes the ailing former leader “draws peace and comfort from the time he’s spending with loved ones”.
The US President spoke by telephone to Graca Machel while she stayed at the 94-year-old’s hospital bedside.
Mr Obama also met two of the Nobel Peace laureate’s daughters and eight of his grandchildren at a private meeting, which lasted 30 minutes, at the Nelson Mandela Centre of Memory in Johannesburg.
In a statement after the visit, he said: “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.
“That’s a legacy that we must all honour in our own lives.”Mr Obama will not see the former South African president, who is critically ill, “out of deference” to him and the family’s wishes
The president is in Pretoria as part of a three-nation Africa tour, which saw him hold bilateral talks with South Africa’s president Jacob Zuma.
After the meeting, Mr Obama told reporters: “Our thoughts and those of Americans and people around the world are with Nelson Mandela and his family and all of South Africans.
“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, has been an inspiration to the world.”
Mr Zuma said Mr Mandela’s condition remains “critical but stable” but the government hopes he will be out of hospital soon.
He added that both leaders were “bound by history as the first black presidents of your respective countries”.
Later, Mr Obama likened Mr Mandela to the first US President George Washington because of the decision of both to step down at the peak of their power.
“What an incredible lesson that is, he said, calling Mr Mandela “one of the greatest people in history”.
Earlier, Mr Obama told reporters in Senegal that he “did not need a photo op” with the anti-apartheid icon and would not be pushing for a visit with him.
The prospect of a public encounter between the first black presidents of South Africa and the US had been eagerly awaited for years, but has now been scuppered by Mr Mandela’s failing health.
The president, who has previously called Mr Mandela a “personal hero”, is due to make a tour on Sunday of Robben Island, the former prison where the anti-apartheid leader passed 18 of the 27 years he spent in jail.
Mr Obama faced protests by South Africans against US foreign policy, especially American drone strikes.
Police fired stun grenades to disperse several hundred protesters who had gathered outside the Soweto campus of the University of Johannesburg, where Mr Obama addressed a town hall meeting with students.
The visit comes after Mr Mandela’s ex-wife Winnie Madikizela-Mandela said the former South African president’s condition has shown “great improvement” over recent days.
Speaking outside the Pretoria hospital on Friday where Mr Mandela is being treated for a recurring lung infection, she said he remained “unwell”.
She said: “It becomes very difficult to understand the seeming impatience and statements like: ‘It is time for the family to let go’.
“And statements like: ‘We are praying for the family not to pull the tubes’.
“Those are insensitive statements that none of you would want made about your parents and grandparents.”