South Africa's ruling African National Congress (ANC) has marked its weakest victory in national elections in a quarter-century, while President Cyril Ramaphosa declared that the vote had given him and others "a firm mandate to build a better South Africa for all".
With all votes counted, the ANC had 57.5 percent, the electoral commission said. It was the worst-ever showing at the polls for the party of the late Nelson Mandela that has ruled since the end of the apartheid system of racial discrimination 25 years ago. The party won 62 percent of the vote in 2014.
Voter turnout was another low at 65 percent, reflecting the frustration of many South Africans after corruption scandals around the ANC that led former president Jacob Zuma to resign last year under party pressure. Turnout was 74 percent in 2014.
Mr Ramaphosa, a Mandela protégé, has vowed to clean up the rot and apologised to South Africans. But his new five-year term is threatened by Zuma allies within the ANC's leadership, who could pressure the party to oust him from power.
Observers have said South Africa's economy, the most developed in sub-Saharan Africa, would be further weakened if Mr Ramaphosa is removed by his own party. He narrowly won the party leadership in late 2017, weeks before Mr Zuma was pushed out.
Mr Ramaphosa's image as a leader willing to rid the government of graft helped the ANC's election showing, political analyst Karima Brown said. "It's a departure from a president who faced continuous allegations of corruption," she said.
But ANC secretary-general Ace Magashule, seen as leading the party faction opposed to Mr Ramaphosa, has said the victory could not be attributed to the president alone.
Widespread disillusionment over the ANC and long-standing issues of high unemployment and poor delivery of basic services had been expected to give top opposition parties a boost in Wednesday's election. A record 48 parties were on the ballot.
Top opposition party the liberal Democratic Alliance (DA) slipped in its share of votes, however, winning 20.7 percent, down from 22.2 percent in 2014. The populist Economic Freedom Fighters (EFF) in just their second showing in parliamentary and presidential elections did gain ground, winning 10.7 percent of the vote, up from 6.3 percent five years ago.
The EFF won support notably among younger voters with its outspoken demands for a bigger share of South Africa's wealth from the country's white minority. It struck a chord in a country where unemployment is 27 percent and many in the black majority struggle to get by. The party also had promised to expropriate white-owned land without compensation and nationalise mines and banks.
With an eye on the country's growing youth population, the "Born Free" generation that never knew apartheid, Mr Ramaphosa noted that "many young people are still outside the fold of voting activity". Some 6 million eligible young voters did not register to vote in this election.
The ANC barely retained control of the country's economic hub of Gauteng province, which includes Johannesburg and the capital, Pretoria, with just over 50 percent of the vote.
In South Africa, the president and parliament are not elected directly. The number of votes won by each party determines how many representatives are sent to the national 400-seat legislature. The president of the country is the leader of the party that gets the most votes. The ANC won 230 seats, the DA 84 and the EFF 44.
With the election over, some South Africans looked forward to moving on."I knew that the ANC would win the elections so my vote for them did not go to waste," said Karabo Kgole, a gas station attendant in Pretoria.