The 94-year-old anti-apartheid icon had been in hospital since December 8 being treated for a lung infection and having gallstones removed, a Government spokesman said.
He will continue to receive medical care at his home in Johannesburg, officials said.
Presidential spokesman Mac Maharaj said that Mr Mandela will receive more medical care at home until he fully recovers.
"We thank the public and the media for the good wishes and for according Madiba and the family the necessary privacy," said Mr Maharaj in a statement, using Mandela's clan name, a term of affection.
Mr Mandela is revered around the world as a symbol of sacrifice and reconciliation, his legacy forged in the fight against apartheid, the system of white minority rule that imprisoned him for 27 years.
The Nobel laureate served one five-year term as president after South Africa's first democratic elections in 1994.