President Obama on Tuesday hailed anti-apartheid icon Nelson Mandela as a “giant of history who moved a nation toward justice, and in the process moved billions around the world” at a memorial service in South Africa for the departed world leader.

Obama praised Mandela as “the last great liberator of the 20th century” in remarks at FNB Stadium in Johannesburg, where tens of thousands of South Africans were joined by dozens of leaders from around the world to pay tribute.

“To the people of South Africa — people of every race and walk of life — the world thanks you for sharing Nelson Mandela with us,” said Obama. “His struggle was your struggle. His triumph was your triumph. Your dignity and hope found expression in his life, and your freedom, your democracy is his cherished legacy.”

Mandela, who died Thursday at the age of 95, fought to end South Africa’s apartheid system and spent 27 years in prison. After being released, he helped negotiate the end of white minority rule and was elected the country’s first black president.

“Mandela taught us the power of action, but also ideas; the importance of reason and arguments; the need to study not only those you agree with, but those who you don’t,” said Obama. “He understood that ideas cannot be contained by prison walls or extinguished by a sniper’s bullet.”

Obama praised Mandela’s work to peacefully transition South Africa to a multiracial democracy and avoid the violence many feared.

“Mandela demonstrated that action and ideas are not enough; no matter how right, they must be chiseled into laws and institutions,” said Obama. “The Constitution that emerged was worthy of this multiracial democracy; true to his vision of laws that protect minority as well as majority rights, and the precious freedoms of every South African. “

The president said that although he fell short, he tried to follow Mandela’s legacy in his own life “as a man and as a president” and urged others to do the same.

“Around the world today, we still see children suffering from hunger and disease, run-down schools, and few prospects for the future. 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,” said Obama.

“We, too, must act on behalf of justice. We, too, must act on behalf of peace. There are too many of us who happily embrace Madiba’s legacy of racial reconciliation but passionately resist even modest reforms that would challenge chronic poverty and growing inequality,” the president continued, using the name by which Mandela is known in South Africa.

Obama was greeted by huge cheers when television cameras showed him arrive at his seat for the service.

Obama was joined at the service by first lady Michelle Obama and former Presidents Clinton and George W. Bush. Bush, former first lady Laura Bush and former Secretary of State Hillary Clinton traveled with Obama on Air Force One to South Africa.

Mandela will receive a state funeral in his hometown of Qunu on Dec. 15. The White House said Obama would send representatives to the funeral on Saturday.

Vice President Joe Biden is also slated to speak at a memorial service for Mandela in Washington on Wednesday at the National Cathedral.