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, Zuma's ex-wife, after a marathon voting process.
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.
Ramaphosa defeated 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.
How the vote happened
Media reports said earlier that the announcement had been delayed, with 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
- Cyril Ramaphosa: Unionist to boss
What were the differences between the two candidates?
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 Zuma as national president in the next few weeks.
The ANC recalled Zuma's predecessor, Thabo Mbeki, in 2008 after Zuma replaced him as ANC leader the previous year.
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 Zuma had backed his former wife.
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.
Cyril Ramaphosa hugs Nkosazana Dlamini-ZumaImage copyrightEPA
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 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?
Zuma's future looks uncertain.
In theory he could remain South African president until national elections in 2019, restricting Ramaphosa's room for manoeuvre.
But it's extremely likely that a victorious 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 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 Ramaphosa's leadership.