South Africa's scandal-hit President Cyril Ramaphosa has been re-elected as the governing ANC's leader to wild cheers from his supporters.
He defeated his rival Zweli Mkhize by 2,476 votes to 1,897.
Mr Ramaphosa won despite being dogged by allegations of money laundering, and a last-minute surge in support for Mr Mkhize, who has also been accused of corruption. Both deny the allegations.
His victory puts him in pole position to lead the ANC in the 2024 election.
But he is still at risk as he is being investigated by police, the tax office and central bank over allegations that he stashed at least $580,000 (£475,000) in a sofa at his private farm, and then covered up its theft.
READ ALSO: South Africa ex-President Zuma sues Ramaphosa
A panel of legal experts, appointed by the speaker of parliament, said that he had a case to answer as he may have both violated the constitution and broken an anti-corruption law.
His supporters burst into song and dance after he was declared the winner, in a result that saw him win by a bigger margin than when he first ran for the leadership of the governing party - the African National Congress - in 2017.
Mr Ramaphosa's re-election bid was bolstered by the fact the ANC used its parliamentary majority to vote down the findings of the panel.
The president has denied any wrongdoing, and has launched legal action to annul the panel's report.
He said the $580,000 came from the sale of buffaloes, but the panel said there was "substantial doubt" over whether a transaction took place.
Mr Mkhize was the health minister in Mr Ramaphosa's government until he was forced to resign last year over allegations of misspending funds set aside to deal with the Covid-19 pandemic.
He too has denied any wrongdoing, and his supporters saw the allegations as an attempt to discredit him.
Mr Ramaphosa was the odds-on favourite to win, but some of Mr Mkhize's supporters looked stunned after the result was announced.
They were confident of victory after offering key posts to other powerful leaders in deals struck just ahead of delegates casting their ballots at the conference.
Both sides denied accusations of vote-buying.
The ANC has been in power since white-minority rule ended in 1994, and is hoping to secure a sixth term in the 2024 parliamentary election. But opinion polls suggest that its vote has shrunk considerably because of widespread corruption in government, high unemployment and poor public services - including constant power cuts.
The ANC elected a new deputy leader, Paul Mashatile, who defeated Mr Ramaphosa's preferred candidate for the second-most powerful post in the party.
Mr Mashatile is now the front-runner to become South Africa's deputy president, and president in the event Mr Ramaphosa is forced out of power.
The president's allies won other powerful posts in the party, including that of secretary-general and national chairperson.
Defeated candidates embraced the winners in a show of unity after a bruising conference.
Supporters of ex-President Jacob Zuma had heckled Mr Ramaphosa during his opening speech at the conference last week.
But no leader from KwaZulu-Natal, the political heartland of Mr Zuma, was elected to any of the ANC's top seven posts, in the latest sign of his and the region's declining influence in the party.