Jacob Zuma, who resigned as South Africa’s president in shame in 2018, is now staging his biggest comeback act yet by running in next month’s parliamentary elections with an upstart opposition party at the top of its ticket — the slot designated for a party’s presidential contender.

Mr. Zuma’s participation in the race is a blow to a faltering African National Congress — the party he once led — which has governed the country since the end of apartheid three decades ago. The A.N.C. and its leader, the country’s current president, Cyril Ramaphosa, are now struggling to win back the trust of voters disillusioned by a stagnant economy and years of corruption.

Mr. Zuma, who is 81, won a big victory on Tuesday when he was cleared by a court to be on the ballot, despite having served time in prison for refusing to testify in a corruption inquiry. On Wednesday, his party — uMkhonto weSizwe — released its list of national candidates with his name at the top.

His party, known as MK, was formed only last December, but has already climbed in the polls, gained ground in local elections and won several legal battles for the right to contest the May 29 election.

If MK does well enough in the parliamentary elections, Mr. Zuma will secure a seat in Parliament. The new lawmakers will then elect the country’s next president. As a member of Parliament, Mr. Zuma would be eligible to be president, or could play kingmaker if the A.N.C. does not win enough seats to form a government — as many political analysts anticipate.

“The victory of the MK marks disaster for the A.N.C.,” said Bheki Mngomezulu, the director for the Center for the Advancement of Non-Racialism and Democracy at Nelson Mandela University.

The country’s Independent Electoral Commission, which had barred him from running, has three days to challenge Tuesday’s ruling allowing Mr. Zuma’s candidacy. The commission said it was now seeking legal advice. But analysts warned that another court challenge so close to a crucial election could damage the commission’s reputation and play in Mr. Zuma’s favor.

It challenged the legality of MK’s electoral registration last month, but lost a court bid. Then it tried to stop Mr. Zuma’s new party, which bears the name of the A.N.C.’s apartheid-era armed wing, from using a name and colors historically associated with the party of Nelson Mandela, arguing that to do so would create confusion among voters. The court ruled in favor of Mr. Zuma then, too.

When the special electoral court sided with Mr. Zuma on Tuesday, it did not give reasons for its decision to allow him to run as a candidate. An earlier decision by the Independent Electoral Commission had ruled him ineligible to run because of the 15-month prison sentence he received for defying a court order in a national corruption inquiry three years ago. Mr. Zuma’s lawyers argued that he was in fact eligible, because he had been released on medical parole two months into his sentence and was later pardoned by President Ramaphosa, his successor and now political rival.

Mr. Zuma, no stranger to the courts, has turned these court appearances into spontaneous political rallies.

Like former U.S. President Donald J. Trump, the Republican front-runner in the coming American election, Mr. Zuma has spun his legal battles into a tale of political persecution that his supporters have lapped up. During his televised court hearing this week, Mr. Zuma’s lawyers accused the Independent Electoral Commission of political bias.

“The attitude has been, ‘Let’s see where we can catch him,’” Dali Mpofu, Mr. Zuma’s lawyer, told the court.

Mr. Zuma’s new party has expressed confidence that these and older court battles, including a corruption trial that has dragged on for years, will not deter voters.

“If we felt there was any merit to those accusations, we probably would have reconsidered,” Lebogang Moepeng, the party’s treasurer general, said in an interview.

He said the party had already attracted 3.8 million members via its online platform, with many new sign-ups coming from Johannesburg and the cities of South Africa’s economic hub, Gauteng Province. This, Mr. Moepeng said, showed support for MK beyond Mr. Zuma’s traditional stronghold, KwaZulu-Natal Province in the east of the country.

The growing support for MK is also threatening the country’s traditional opposition parties. Of all the A.N.C. leaders, many South Africans still see Mr. Zuma as the one who is “closest to the people,” said Mr. Mngomezulu, the political analyst.

In Kwa-Zulu Natal, where Mr. Zuma’s face began appearing on campaign posters earlier this year, the A.N.C. maintained that it did not feel threatened by having Mr. Zuma’s face on the ballot now, too.

“It has no impact on the A.N.C.,” said Nhlakanipho Ntombela, who heads the party’s campaign efforts in the province.

Although the party’s membership swelled when Mr. Zuma came to power in 2014, Mr. Ntombela added, its support then declined while he was president.