With all votes counted, the ANC had 57.5%, 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% of the vote in 2014.
Voter turnout was another low at 65%, 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% in 2014.
Ramaphosa, a Mandela protege, has vowed to clean up the rot and apologized 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 Ramaphosa is removed by his own party. He narrowly won the party leadership in late 2017, weeks before Zuma was pushed out.
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 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 slipped in its share of votes, however, winning 20.7%, down from 22.2% in 2014. The populist Economic Freedom Fighters in just their second showing in parliamentary and presidential elections did gain ground, winning 10.7% of the vote, up from 6.3% 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% and many in the black majority struggle to get by. The party also had promised to expropriate white-owned land without compensation and nationalize mines and banks.
With an eye on the country's growing youth population, the "Born Free" generation that never knew apartheid, 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% 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 waste," said Karabo Kgole, a gas station attendant in Pretoria.
Follow Africa news at https://twitter.com/AP_Africa