Zimbabwe's parliament erupted in cheers as the speaker announced the resignation of President Robert Mugabe.
The speaker stopped impeachment proceedings to say they had received a letter from Mr Mugabe confirming the resignation "with immediate effect".
"My decision to resign is voluntary on my part and arises from my concern for the welfare of the people of Zimbabwe and my desire for a smooth, non-violent transfer of power," said Mr Mugabe in the letter which was read out in parliament, sparking cheers and dancing.
It is an extraordinary end for the world's oldest head of state after 37 years in power.
Mr Mugabe said he is resigning immediately and voluntarily in order to have a "smooth transfer of power" .
The letter was read out in a cheering, dancing Parliament, which had been pursuing impeachment of the 93-year-old Mr Mugabe.
Cars began honking horns and people cheered in the streets, as the news spread like wildfire across the capital, Harare.
The resignation comes at the end of a week of events that began with the military moving in last week, angered by Mr Mugabe's firing of his long-time deputy and the positioning of the unpopular first lady to succeed him.
Impeachment allegations against Mr Mugabe included that he "allowed his wife to usurp constitutional power" and that he is "of advanced age" and too incapacitated to rule.
Mr Mugabe was also accused of allowing unpopular first lady Grace Mugabe to threaten to kill the recently fired Vice President Emmerson Mnangagwa and other officials.
Mr Mugabe's resignation brought an end to the impeachment proceedings begun by the ruling ZANU-PF party after its Central Committee voted to oust the president as party leader and select recently fired vice president Emmerson Mnangagwa as his replacement.
A ruling party official said Mr Mnangagwa would take over as leader within 48 hours.
Currently in exile, Mr Mnangagwa served for decades as Mr Mugabe's enforcer, with a reputation for being astute and ruthless.
Before the resignation, crowds rallied outside Parliament, dancing and singing.
Some people placed photos of Mr Mugabe in the street so that cars would run over them.
Opposition leader Morgan Tsvangirai of the MDC party said the culture of the ruling party "must end" and everyone must put their heads together and work towards free and fair elections.
Earlier on Tuesday, Mr Mnangagwa said in a statement that Mr Mugabe should acknowledge the nation's "insatiable desire" for a leadership change and resign immediately.
Mr Mnangagwa added to immense pressure on Mr Mugabe to quit after nearly four decades in power, during which he evolved from a champion of the fight against white minority rule into a figure blamed for a collapsing economy, government dysfunction and human rights violations.
"The people of Zimbabwe have spoken with one voice and it is my appeal to President Mugabe that he should take heed of this clarion call and resign forthwith so that the country can move forward and preserve his legacy," Mr Mnangagwa said in his statement, after more than a week of silence.
Mr Mnangagwa, who fled the country and has not appeared in public during the past week's political turmoil, said Mr Mugabe had invited him to return to Zimbabwe "for a discussion" on recent events. However, he said he will not return for now, alleging that there had been plans to kill him at the time of his firing.
"I will be returning as soon as the right conditions for security and stability prevail," said Mr Mnangagwa, who has a loyal support base in the military. "Never should the nation be held at ransom by one person ever again, whose desire is to die in office at whatever cost to the nation."
Zimbabwe's polarising first lady, Grace Mugabe, had been positioning herself to succeed her husband, leading a party faction that engineered Mr Mnangagwa's removal.
The prospect of a dynastic succession alarmed the military, which confined Mr Mugabe to his home last week and targeted what it called "criminals" around him who allegedly were looting state resources - a reference to associates of the first lady.
Mr Mnangagwa was targeted by US sanctions in the early 2000s for undermining democratic development in Zimbabwe, according to the Atlantic Council, a US-based policy institute. However, J Peter Pham, an Africa expert at the council, noted that some Zimbabwean opposition figures have appeared willing to have dialogue with Mr Mnangagwa in order to move the country forward and that the international community should consider doing the same.
"We're not saying whitewash the past, but it is in the interests of everyone that Zimbabwe is engaged at this critical time," Mr Pham said in a statement.
Regional leaders continued efforts to find a solution to the political turmoil, with South Africa's state-run broadcaster reporting that the presidents of South Africa and Angola would travel to Zimbabwe on Wednesday to meet with "stakeholders" in the political crisis, including Mr Mugabe and the military.