Mr Mandela, who turned 94 in July, had been in hospital for nearly three weeks, sparking a flurry of concern in South Africa and around the world.
He was discharged from hospital late on Wednesday to his home in Houghton, an affluent suburb of Johannesburg, where he will continue to receive home-based care, the office of the president said.
“He is not yet fully recovered, but he has sufficiently moved forward so that he can be discharged,” Mac Maharaj, a spokesman for President Jacob Zuma told eNCA, a local television network on Thursday. “He is sufficiently well to be home.”
It was the elder statesman’s longest stay in hospital since his release from prison in 1990.
Mr Mandela was previously treated for acute respiratory infection in January last year, and he had suffered from tuberculosis in 1988 during the 27 years he spent in prison under the apartheid regime. He was last admitted to hospital in February because of abdominal pain but was discharged the following day.
Mr Mandela has been frail for several years and spends most of his time at his rural home in Qunu, a village in the Eastern Cape Province.
The Nobel Peace Prize winner is revered around the world after he made the transition from freedom fighter to become South Africa’s first black president and led his nation’s dramatic transformation from apartheid to democracy.
After his release from prison in February 1990, Mr Mandela steered the African National Congress, the liberation movement, to an overwhelming victory at the country’s first democratic election in 1994.
He spent the next five years focusing much of his efforts on reconciling his divided nation, reassuring whites and blacks, and helping South Africa avoid the bloodshed many had predicted.
He stepped down in 1999 after serving one term – a rare act among Africa’s long list of liberation leaders who took over their countries – and was succeeded by Thabo Mbeki.
He officially retired from public life in 2004 and has not been involved in day-to-day politics for years and he is rarely seen in public.
South Africa, which is Africa’s largest economy, has gone on to prove itself to be politically and economically stable. The presidency has changed hands three times democratically since 1994.