South Africa's ruling African National Congress party led by President Cyril Ramaphosa has suffered a setback in the local elections, winning 31 percent of the national vote with 99 percent of the ballots counted.