Tens of thousands of spectators have braved foul weather to join heads of state from around the world in celebrating the life of Nelson Mandela in South Africa.
In a speech that received thunderous applause and a standing ovation from scores of heads of state, Mr Obama urged people to apply the lessons of Mr Mandela, who emerged from 27 years in prison under a racist regime, embraced his enemies when he finally walked to freedom and promoted forgiveness and reconciliation in South Africa.
"We, too, must act on behalf of justice. We, too, must act on behalf of peace," said Mr Obama, who like Mr Mandela became the first black president of his country. Mr Obama said that when he was a student, Mr Mandela "woke me up to my responsibilities - to others, and to myself - and set me on an improbable journey that finds me here today."
Police were expecting a crushing crowd at FNB stadium and had set up overflow points with big screen TVs, but the weather and public transport problems rain kept many people away. The 95,000-capacity stadium was only two-thirds full.
Addressing the memorial service for Mr Mandela, who died last Thursday aged 95, Mr Obama pointed out that "around the world today, men and women are still imprisoned for their political beliefs; and are still persecuted for what they look like, or how they worship, or who they love."
Among the nearly 100 heads of state and government were some from countries like Cuba that do not hold fully democratic elections. On the way to the podium, Mr Obama shook hands with Cuban President Raul Castro, underscoring a recent warming of relations between the countries.
In contrast to the wild applause given to Mr Obama, South African President Jacob Zuma was booed. Many South Africans are unhappy with him because of state corruption scandals, although his ruling African National Congress, once led by Mr Mandela, remains the front-runner ahead of elections next year.
But otherwise the mood was celebratory. A dazzling mix of royalty, statesmen and celebrities was in attendance.
Thabo Mbeki, the former South African president who succeeded Mr Mandela, got a rousing cheer as he entered the stands. French President Francois Hollande and his predecessor and rival, Nicolas Sarkozy, arrived together. United Nations Secretary-General Ban Ki-moon waved and bowed to spectators who sang praise for Mr Mandela, seen by many South Africans as the father of the nation.
Rohan Laird, the 54-year-old head of a health insurance company, said in the stadium that he grew up during white rule in a "privileged position" as a white South African and that Mr Mandela helped whites work through a burden of guilt.
"His reconciliation allowed whites to be released themselves," he said. "I honestly don't think the world will see another leader like Nelson Mr Mandela."
Workers were still welding at a VIP area as the first spectators arrived amid an enormous logistical challenge of organising the memorial for Mr Mandela.
His widow, Graca Machel, and former wife Winnie Madikizela-Mr Mandela were at the stadium, and gave each other a long hug before the ceremonies began. So were actress Charlize Theron, model Naomi Campbell and singer Bono.
Tuesday was the 20th anniversary of the day when Mr Mandela and South Africa's last apartheid-era president, F.W. de Klerk, received the Nobel Peace Prize for their efforts to bring peace to their country. Mr De Klerk, a political rival who became friends with Mr Mandela, was also in the stadium.
Mr Mandela said in his Nobel acceptance speech at the time: "We live with the hope that as she battles to remake herself, South Africa will be like a microcosm of the new world that is striving to be born."
The stadium was also the spot where Mr Mandela made his last public appearance at the closing ceremony of the World Cup.
After the memorial, his body will lie in state for three days at the Union Buildings in Pretoria, once the seat of white power, before burial on Sunday in his rural childhood village of Qunu in Eastern Cape Province.