He was speaking in the capital, Pretoria, after talks with President Jacob Zuma.
Mr Mandela, South Africa’s first black president, has been critically ill in hospital for nearly a week.
Earlier, Mr Obama said he would not visit the 94-year-old in hospital out of respect for his family.
In Pretoria, Mr Obama said the former leader’s example was a beacon of “the power of principle, of people standing up for what’s right”.
Mr Zuma said Mr Obama and Mr Mandela were “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”.
He said Mr Obama’s visit was “well timed” to take advantage of a growing market in South Africa, and called for greater US investment.
Mr Obama, who is travelling with his family, arrived in South Africa from Senegal on Friday evening.
During his weekend trip, the US president will visit Robben Island, where Mr Mandela was imprisoned for 18 years.