Johannesburg (CNN) -- Nelson Mandela has been discharged from the Pretoria hospital where he had been receiving treatment since June, the South African president's office said Sunday.
He will continue his recovery at home.
"Madiba's condition remains critical and is at times unstable," President Jacob Zuma's office said, referring to the revered leader's clan name. "Nevertheless, his team of doctors are convinced that he will receive the same level of intensive care at his Houghton home that he received in Pretoria."
Mandela, 95, was hospitalized June 8 because of a lung infection. He marked his July birthday at the Pretoria hospital where he has been surrounded by relatives.
"During his stay in hospital from the 8th of June 2013, the condition of our former President vacillated between serious to critical and at times unstable," the office said. "Despite the difficulties imposed by his various illnesses, he, as always, displays immense grace and fortitude."
There was some confusion Saturday when two sources close to Mandela said he had returned home -- only to be contradicted by the president's office, which said he was still hospitalized.
"The family mistakenly thought Mandela had been taken to his Johannesburg home early Saturday morning," the source then told CNN.
The frail icon has not appeared in public for years, but he retains his popularity as the father of democracy and emblem of the nation's fight against apartheid.
Mandela became an international figure while enduring 27 years in prison for fighting against apartheid, the country's system of racial segregation.
He became the nation's first black president in 1994, four years after he was freed from prison.
Mandela's impact extends far beyond South African borders. After he left office, he mediated conflicts in Africa and the Middle East.
His history of lung problems dates to his imprisonment on Robben Island, and he has battled respiratory infections since then.