South Africa's ruling African National Congress (ANC) has selected Cyril Ramaphosa to succeed President Jacob Zuma as the party's leader.
The country's deputy president defeated former cabinet minister Nkosazana Dlamini-Zuma, Mr Zuma's ex-wife, after a marathon voting process.
Mr Ramaphosa is in a strong position to become president in 2019 polls.
The leadership battle caused fierce political infighting, raising fears the party might split before the election.
Mr Ramaphosa defeated Ms Dlamini-Zuma by 2,440 votes to 2,261, an ANC spokesperson announced.
The result triggered celebrations among party delegates in Johannesburg and also on the streets of the city.
Media reports said earlier that the announcement had been delayed, with Ms Dlamini-Zuma's camp demanding a recount.
The voting process started on Sunday.
Cyril Ramaphosa at a glance:
- Born in Soweto, Johannesburg, in 1952
- Detained in 1974 and 1976 for anti-apartheid activities
- Launched the National Union of Mineworkers in 1982
- Chairman of the National Reception Committee which prepared for Nelson Mandela's release from prison in 1990
- Became an MP and chairman of constitutional assembly in 1994
- Moved full-time into business in 1997, becoming one of South Africa's richest businessmen
- On Lonmin board during 2012 Marikana massacre
- Became South Africa's deputy president in 2014
- Elected ANC leader in 2017
What were the differences between the two candidates?
Mr Ramaphosa, 65, has spoken out strongly against state corruption and has the backing of the business community.
He campaigned as the anti-Zuma candidate, promising to target corruption, and his victory could mean that the ANC decides to recall Mr Zuma as national president in the next few weeks.
The Supreme Court ruled in October that Mr Zuma should face corruption, fraud, racketeering and money-laundering charges.
The ANC recalled Mr Zuma's predecessor, Thabo Mbeki, in 2008 after Mr Zuma replaced him as ANC leader the previous year.
Ms Dlamini-Zuma, 68, had been critical of the enduring power of white-owned businesses and had pledged to tackle what she said was continued racial inequality.
Analysts said that Mr Zuma had backed his former wife.
The ANC election came amid declining support for the party, though opinion polls still suggest backing of about 50%.
Lebo Diseko, BBC News, Johannesburg
To say the atmosphere inside the plenary was electric would be quite the understatement - the singing inside the hall reached crescendo point as it was announced that Cyril Ramaphosa is the new president of the ANC.
There was a touching moment when Nkosazana Dlamini-Zuma came on stage and hugged the man who beat her - by less than 200 votes - to the top job in the party, and put a halt to her ambition to be South Africa's first female president.
The ANC has been torn apart by infighting of late, and the leadership battle was particularly bitter.
There is much work ahead for the new leader of the liberation movement.
Not only does Mr Ramaphosa need to unite his party, he also needs to convince the electorate that the ANC still represents the issues of the people it fought to hard to bring freedom to.
What next for Zuma?
Andrew Harding, BBC News, Johannesburg
Mr Zuma's future looks uncertain.
In theory he could remain South African president until national elections in 2019, restricting Mr Ramaphosa's room for manoeuvre.
But it's extremely likely that a victorious Mr Ramaphosa will seek the "recall" of President Zuma by the ANC.
If that happens, then things could move very quickly, and a President Ramaphosa would probably move fast to remove Mr Zuma's allies from key positions.
The heads of the National Prosecuting Authority and the state power utility have, for instance, faced particular criticism.
Opinion polls suggest that the ANC stands a better chance of shoring up its waning popular support and winning the 2019 elections under Mr Ramaphosa's leadership.
Read more from Andrew: