Doctors treating Mandela waited to perform the endoscopic surgery as they wanted to first attend to his lung ailment, presidential spokesman Mac Maharaj said in a statement. Mandela has been hospitalized since Dec. 8.
"The procedure was successful and Madiba is recovering," Maharaj said, using Mandela's clan name as many do in South Africa as a sign of affection.
South Africa reveres the aged leader for being the nation's first democratically elected president who sought to bring the country together after centuries of racial division.
Mandela largely retired from public life after serving one five-year term as president and has lived a mostly private life since. He last made a public appearance when his country hosted the 2010 World Cup soccer tournament. Mandela has also grown more frail in recent years, with his grip on politics in the nation ever slackening.
He was admitted last week to a hospital in South Africa's capital, Pretoria, the government has said. However, government officials have contradicted themselves in recent days about Mandela's location, raising questions about who is actually treating him.
With the government refusing to say where Mandela is, concern has been growing and rumors continue to fly across this nation of 50 million people about Mandela's health.
Mandela has a history of lung problems, after falling ill with tuberculosis in 1988 toward the tail-end of his 27 years in prison before his release and subsequent presidency. While doctors said at the time the disease caused no permanent damage to his lungs, medical experts say tuberculosis can cause problems years later for those infected.
The Nobel laureate had an acute respiratory infection in January 2011. Following the chaos that surrounded Mandela's stay at a public hospital then, the South African military took charge of his care and the government took over control of the information about his health.