In a speech that received thunderous applause, Obama urged people to apply the lessons of 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 Obama, who like Mandela became the first black president of his country. Obama said that when he was a student, 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 foul weather and public transportation problems kept many people away. The 95,000-capacity stadium was only two-thirds full.
Addressing the memorial service for Mandela, who died Thursday at age 95, 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 don't hold fully democratic elections. On the way to the podium, Obama shook hands with Cuban President Raul Castro, underscoring a recent warming of relations between Cuba and the U.S.
In contrast to the wild applause given to Obama, South African President Jacob Zuma was booed. Many South Africans are unhappy with Zuma because of state corruption scandals, though his ruling African National Congress, once led by Mandela, remains the front-runner ahead of elections next year.
Some of the dozens of trains reserved to ferry people to the stadium in Soweto, a township which revolted in 1976 against white rule, were delayed due to a power failure. A Metrorail services spokeswoman, Lilian Mofokeng, said more than 30,000 mourners were successfully transported by train.
The mood was celebratory. A dazzling mix of royalty, statesmen and celebrities was in attendance.
Thabo Mbeki, the former South African president who succeeded 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 Mandela, seen by many South Africans as the father of the nation.
"I would not have the life I have today if it was not for him," said Matlhogonolo Mothoagae, a postgraduate marketing student who arrived hours before the stadium gates opened. "He was jailed so we could have our freedom."
Rohan Laird, the 54-year-old CEO 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 Mandela helped whites work through a burden of guilt.
"His reconciliation allowed whites to be released themselves," Lair said. "I honestly don't think the world will see another leader like Nelson Mandela."
Workers were still welding at a VIP area as the first spectators arrived amid an enormous logistical challenge of organizing the memorial for Mandela, who died Dec. 5 in his Johannesburg home at the age of 95.
Mandela's widow, Graca Machel, and former wife Winnie Madikizela-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 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. De Klerk, a political rival who became friends with Mandela, was also in the stadium.
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 sounds of horns and cheering filled the stadium. The rain was seen as a blessing among many of South Africa's majority black population.
"In our culture the rain is a blessing," said Harry Tshabalala, a driver for the justice ministry. "Only great, great people are memorialized with it. Rain is life. This is perfect weather for us on this occasion."
People blew on vuvuzelas, the plastic horn that was widely used during the World Cup soccer tournament in 2010, and sang songs from the era of the anti-apartheid struggle decades ago.
"It is a moment of sadness celebrated by song and dance, which is what we South Africans do," said Xolisa Madywabe, CEO of a South African investment firm.
The soccer venue was also the spot where 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 Sunday in his rural childhood village of Qunu in Eastern Cape Province.
Police promised tight security, locking down roads kilometers (miles) around the stadium. However, the first crowds entered the stadium without being searched.
John Allen, a 48-year-old pastor from the U.S. state of Arkansas, said he once met Mandela at a shopping center in South Africa with his sons.
"He joked with my youngest and asked if he had voted for Bill Clinton," Allen said. "He just zeroed in on my 8-year-old for the three to five minutes we talked."