30 June 2013 Last updated at 21:09 GMT
Mr Obama wrote in the guest book: “The world is grateful for the heroes of Robben Island”
US President Barack Obama has toured Robben Island – the jail in which Nelson Mandela was kept for 18 years.
He said he and his family were “deeply humbled” to visit the prison once inhabited by Mr Mandela – who remains critically ill in hospital.
Mr Obama went on to give a speech at the University of Cape Town and launch a multi-billion-dollar electricity initiative.
The US leader did not visit Mr Mandela, but met the Mandela family in private.
Security was stepped up during this final Cape Town leg of his time in South Africa, following clashes on Saturday between riot police and anti-Obama protesters in Soweto.
More than three weeks after Nelson Mandela was taken to Medi-Clinic Heart Hospital in Pretoria, there is still a steady stream of well-wishers leaving flowers and tributes to add to the huge collection outside the gates.
On Sunday morning, two church groups were singing hymns, while veterans from Umkhonto we Sizwe (MK), the ANC’s armed wing set up by Mr Mandela, arrived with a portrait of their founder wearing a military uniform.
The tributes come from around the world – Pakistan, Mexico and France – as well as several African countries. And in a testimony to Mr Mandela’s dream of creating a rainbow nation, all of South Africa’s racial groups were represented.
As she left a bunch of white chrysanthemums, Raksha Daya said that like many South Africans, she connects with the former president on a deeply personal level, like a grandfather. “It’s a sense of love.”
Mr Obama and the first family visited Mr Mandela’s bleak cell as well as the lime quarry – overlooked by a concrete watchtower – where anti-apartheid fighters including Mr Mandela were forced to undertake hours of back-breaking labour.
Mr Mandela was at the prison for 18 years and his long history of lung problems can be traced to the tuberculosis he contracted there – which he attributed to the dampness of his cell.
Later, Mr Obama wrote in the guest book in the prison courtyard: “On behalf of our family, we’re deeply humbled to stand where men of such courage faced down injustice and refused to yield.
“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.”
Mr Obama also visited a community project before delivering a keynote address at the University of Cape Town.
It was the same venue where 47 years ago, US Senator Robert Kennedy gave his famed “ripple of hope” speech, which gave inspiration to those fighting the racially divisive policies of apartheid rule and linked their struggle with that of the US civil rights movement.