President Jacob Zuma of South Africa addressing the nation in Pretoria on Wednesday.

President Jacob Zuma of South Africa, a master tactician who survived a string of scandals and harsh court judgments during his nearly nine-year presidency, agreed on Wednesday to step down, repudiated by the governing African National Congress Party, cornered by opposition parties and abandoned by millions of voters.

In an address to the nation Wednesday night, Mr. Zuma said he was resigning even though he disagreed with the party’s decision ordering him to do so.

“I have therefore come to the decision to resign as the president of the Republic with immediate effect, even though I disagree with the decision of the leadership of my organization,” he said at the end of a lengthy address on television. “I have always been a disciplined member of the A.N.C.”

It is a humiliating end for Mr. Zuma, a charismatic anti-apartheid hero who was imprisoned on Robben Island with Nelson Mandela and was once the A.N.C.’s intelligence chief.

Initially he inspired hope in millions of South Africans, especially the poorest. But, tainted by numerous accusations of misconduct, he came to symbolize the corruption that flourished during his time in office.

Influence-peddling in his administration was so widespread, according to the nation’s former public protector, that it became a form of state capture in which Mr. Zuma’s business partners or friends influenced government decisions in their personal interest.

Now, his departure as president leaves South Africa with a disillusioned electorate, a weakened economy and a tarnished image in the rest of Africa.

Only hours before his resignation he had sounded defiant and aggrieved during a live interview with the state broadcaster SABC, after party leaders had threatened to remove him through a no-confidence vote in Parliament on Thursday. He had indicated strongly that he would not resign, saying the party’s effort to pull him from office was “unfair,” that he was being “victimized,” and that he had done nothing wrong.

A banner bearing a portrait of Cyril Ramaphosa, the A.N.C. leader, at the party’s anniversary celebration last month. CreditMujahid Safodien/Agence France-Presse — Getty Images
The deputy president, Cyril Ramaphosa — whose election as A.N.C. leader in December set off a power struggle with Mr. Zuma — immediately became acting president. On Thursday, Mr. Ramaphosa is almost certain to be chosen by Parliament to become the nation’s fifth president since the end of apartheid in 1994; all have been members of the A.N.C.

The resignation was the culmination of a long internal fight, pitting Mr. Zuma’s supporters against an ascendant faction led by Mr. Ramaphosa, who pushed the president to step down before the end of his full term in mid-2019. The balance finally tipped against Mr. Zuma, when the majority of party leaders concluded that the A.N.C.’s interests, and their own, would be better served under a new head of state.

On Tuesday, after more than a week of failed efforts by Mr. Ramaphosa to ease Mr. Zuma out office, party leaders ordered Mr. Zuma to step down, saying his continued presence as the nation’s leader would “erode the renewed hope and confidence among South Africans,” and indicating that he was hurting the party’s electoral prospects.

Mr. Zuma’s administration appeared to schedule an address to the nation by Mr. Zuma at 10 a.m. on Wednesday, but then issued a statement saying no such briefing was planned an hour before it was scheduled to start.

As Mr. Zuma remained defiantly silent, the police’s investigative unit — which has long been subject to political interference — raided the residence in Johannesburg of the Guptas, a family with wide-ranging business interests and close ties to one of the president’s sons and his political allies, and arrested three people.

The intended message, political analysts said, was that those closest to Mr. Zuma, or even Mr. Zuma himself, could be next unless he acceded to the party’s order to quit.

Then, a few hours after that, as Mr. Zuma gave no indication of responding to his party’s order, A.N.C. leaders escalated the pressure. If the president did not resign by the end of the day, they said, they would move to remove him through a vote of no confidence the next day.

“The ball is in his court,” said Paul Mashatile, the party’s treasurer general and a Ramaphosa ally.
Mr. Zuma broke his silence with the SABC interview shortly after that, before finally resigning during his address to the nation.

The developments were a clear sign of how much had changed in the two months since Mr. Ramaphosa was chosen to succeed Mr. Zuma as the leader of the A.N.C., creating what South Africans refer to as the two centers of power — the presidency and the head of the party.

Mr. Zuma, seemingly untouchable just a couple of months ago, was gone in just 58 days.

For years, Mr. Zuma — as the leader of both the party and the nation — had relied on his party’s support to fend off opposition-led no-confidence votes in Parliament and damning rulings by the nation’s highest courts.

Mr. Zuma’s reversal in fortunes began in December, when his choice as party successor, Nkosazana Dlamini-Zuma, a veteran politician and his former wife, lost to Mr. Ramaphosa by a small margin.

Mr. Ramaphosa’s election was considered a victory for reformers inside the A.N.C. After his election, South Africa’s currency, the rand, and overall business confidence have risen.

In recent weeks, Mr. Ramaphosa’s supporters lobbied for Mr. Zuma’s early exit. They argued that Mr. Ramaphosa needed time before the 2019 elections to rebuild the party and woo back voters, especially in the urban black middle class.

Pushing back, Mr. Zuma’s followers said he should be allowed to complete his term. But the momentum was not in their favor, and other challenges, potentially embarrassing to both Mr. Zuma and the party, lay ahead.

Mr. Zuma faced possible corruption charges for an arms deal in the 1990s, before he was president, as well as possible impeachment proceedings stemming from another corruption case, related to the misuse of public funds for upgrades to his homestead.

Mr. Zuma’s resignation saved the A.N.C. from a potentially embarrassing confrontation in Parliament. It is almost certain that the party would have succeeded in passing the no-confidence vote, given its dominance in the legislative body.

But the spectacle of a party finally turning against a leader it had protected steadfastly for nearly nine years would have likely resulted in awkward verbal footwork by A.N.C. lawmakers and stinging attacks by a reinvigorated opposition.

The same A.N.C. lawmakers, who had until a couple of months ago always offered a full-throated defense of Mr. Zuma’s conduct in a series of scandals, would have been forced to proffer reasons to remove him in Parliament — exposing the party to charges of hypocrisy and expediency, and casting doubt on Mr. Ramaphosa’s pledge to reform it.

The A.N.C.’s difficult position was on clear display on Tuesday. At a news conference at its headquarters in Johannesburg, Ace Magashule — who is third in the party’s hierarchy and has traditionally acted as its spokesman — struggled to explain why the party was asking for Mr. Zuma’s resignation.

Mr. Magashule said the corruption accusations against the president had played no role, saying, “We did not take these decisions because Comrade Jacob Zuma has done anything wrong.”

Mr. Magashule’s remarks suggested the party might be reluctant to deal head-on with the culture of corruption that was endemic under Mr. Zuma — and also that it was concerned about its success in future elections.

In the 2016 local elections, the A.N.C. lost control over the nation’s biggest cities after it was deserted by traditional supporters disillusioned by Mr. Zuma’s conduct; some party officials have since warned that it might face a similar fate in national elections in 2019.

But party leaders did not explain, as Mr. Zuma himself pointed out in the television interview, why they had loyally backed him until two months ago and were now demanding his resignation. What had changed, beyond the fact that there was now a new A.N.C. leader who wanted him out?

“Nobody’s saying what I’ve done,” Mr. Zuma said in his television interview.