South African President Jacob Zuma resigned on Wednesday as the ruling ANC party finally turned against him after nine years of corruption scandals, economic slowdown and falling popularity.
Zuma railed against the African National Congress (ANC) for "recalling" him from office and threatening to oust him via a parliament no-confidence vote due on Thursday.
In a 30-minute national television address, Zuma said he had "come to the decision to resign as president of the republic with immediate effect".
Zuma has been in a power struggle with multi-millionaire former businessman Cyril Ramaphosa, the deputy president who now becomes interim president.
Ramaphosa, who won control of the ANC when he was elected as its head in December, is set to be voted in by lawmakers as South Africa's new president on Thursday or Friday.
Zuma, whose reputation has been stained by years-long allegations of graft, complained that the ANC party had never explained to him why he had to leave office.
In an earlier TV interview on Wednesday he said he had received "very unfair" treatment from the party he joined in 1959 and in which he had fought for decades against apartheid white-minority rule.
He said he was angered over "the manner in which the decision is being implemented... I don't agree as there is no evidence of if I have done anything wrong."
The party's national executive committee ordered his recall from office on Tuesday, after a 13-hour meeting at a hotel outside Pretoria.
ANC officials had said that if Zuma did not resign on Wednesday, the party's lawmakers in the Cape Town parliament would vote out Zuma on Thursday.
But senior party official Jesse Duarte said after the resignation that "we are not celebrating".
"We have had to recall a cadre of the movement that has served this organisation for over 60 years, it's not a small matter," she added.
On Wednesday morning, police had raided the Johannesburg home of the Gupta business family, which is accused of overseeing a web of corruption under Zuma's rule.
Police said three unidentified people had been arrested in investigations into "Vrede Farm" -- allegations that millions of dollars of public money meant for poor dairy farmers were syphoned off by the Guptas.
Local media reported that Zuma had been pushing for an exit deal that included covering his legal fees fighting multiple criminal charges -- but he denied the allegations in his resignation speech.
One case against him relates to 783 payments he allegedly received linked to an arms deal before he came to power.
Many other graft allegations have centred on the three Gupta brothers, who are accused of unfairly obtaining lucrative government contracts and even being able to choose Zuma's ministerial appointments.
Zuma has admitted he is friends with the Guptas, originally from India, but has denied any wrongdoing.
The political wrangling in recent weeks plunged South Africa -- the continent's most developed economy -- into confusion over who was running the country, with last Thursday's annual State of the Nation address cancelled at the last-minute.
Decline of Mandela's party
Zuma's presidency was marred by slow economic growth, continuing racial inequality and record unemployment that fuelled public frustration.
He was scheduled to stand down next year after serving the maximum two terms since coming to power in 2009.
In local polls in 2016, the ANC recorded its worst electoral result since coming to power in 1994 with Nelson Mandela at the helm as white-minority rule fell.
Ramaphosa, 65, the deputy president, must revive the economy and crack down on what he has admitted is rampant government corruption if he is to boost the party's tarnished reputation before a tricky election next year.
He is a former trade unionist and Mandela ally who led talks to end apartheid in the early 1990s and then became a hugely wealthy businessman before returning to politics.
Zuma's hold over the ANC was shaken in December when his chosen successor -- his former wife Nkosazana Dlamini-Zuma -- narrowly lost to Ramaphosa in a vote for the new party leader.