The South African parliament has narrowly voted to keep President Jacob Zuma in office in a secret no-confidence motion against the scandal-plagued leader.

Members of the 400-seat parliament voted, 198 to 177 with nine abstentions, on Tuesday against the proposal to remove the president.

The opposition needed at least 50 votes from the ruling African National Congress members to overthrow Zuma.

OPINION: Even if Zuma goes, South Africa will remain divided

ANC members erupted in cheers as the result of the voting was announced.

Reacting to the vote, Zuma told supporters gathered outside the parliament in Cape Town: "It's difficult to defeat the ANC. They always try."

The vote has become a test of ANC unity as senior party figures have increasingly become critical of their leader.

Al Jazeera's Haru Mutasa, reporting from Cape Town, said that the "tight result" indicated that some of Zuma's party mates voted for him to go.

"Zuma knows that the vote would be tight. It means he is not as popular as he used to be. There are people within his party who are frustrated about the way he is running the country," our correspondent said.

'Toxic mix of corruption, nepotism'

Mmusi Maimane, leader of the main opposition Democratic Alliance party said, praised the "brave" ANC politicians who voted against Zuma.

"Today's motion of no confidence result is closer than anyone expected," he said. "Jacob Zuma is the manifestation of what the ANC has become - a toxic mix of corruption, cronyism and nepotism."

Before the voting, Maimane made an impassioned case for Zuma's removal.

"I plead with you, let us put the people of South Africa first and vote to remove Jacob Zuma today," Mmusi Maimane said.

Speaking on behalf of the ruling ANC, deputy chief whip Doris Dlakude said the motion against Zuma amounted to a "power grab" by the opposition.

"The ANC rejects this motion with the contempt it deserves," she said.

The president, who came to power in 2009, has been implicated in multiple corruption scandals, while the country's economy has fallen into recession and unemployment has risen to record levels.

The 75-year-old is due to step down as head of the ANC in December, and as president before the 2019 general election.

On Monday, Parliament Speaker Baleka Mbete announced that the no-confidence motion against Zuma would be voted on through a secret ballot.

The Speaker's decision has been subject to a long legal battle waged by opposition parties, with the Constitutional Court ruling that a secret ballot was permissible.