Barack Obama says he was "deeply humbled" by a visit to the cell where Nelson Mandela spent years as a prisoner.
The US president paid tribute to Mandela and other anti-apartheid inmates of Robben Island, who "refused to yield" in the face of racist white minority rule.
Obama, accompanied by his wife Michelle and young daughters Sasha and Malia, visited the bleak lime quarry where 34 anti-apartheid leaders - including Mandela - endured hours of backbreaking work.
He stood alone, looking out the barred window of the small damp cell where Mandela spent two thirds of his 27 years in prison, his darkest days of his detention.
After touring the sandy wind-swept island, Obama took a few minutes to write a note in the visitors book.
"On behalf of our family we're deeply humbled to stand where men of such courage faced down injustice and refused to yield," he wrote.
"The world is grateful for the heroes of Robben Island, who remind us that no shackles or cells can match the strength of the human spirit."
Mandela's continued hospitalisation has cast a pall over Obama's much awaited three-nation visit to Africa.
Obama will later make Mandela the keystone of an address at the University of Cape Town, citing his unifying legacy as a blueprint for a new generation in emerging Africa.
Mandela's illness placed Obama in a tricky political spot, forcing him to balance his desire to push for a new economic relationship with Africa, with the need to properly honour his hero, who has been in intensive care for more than three weeks.
On Saturday, Obama and his wife Michelle called Mandela's wife Graca Machel, and the president then privately visited several daughters and grandchildren of Mandela, to offer support and prayers.
But he decided against rolling up in his massive entourage at the Pretoria hospital where the 94-year-old Mandela lies, worried that he would disturb his peace.