South Africa's president has cut short a visit to Britain to return home and deal with violent protests in a provincial capital.

President Cyril Ramaphosa has left the Commonwealth summit in London to respond to the turmoil in the North West capital of Mahikeng, where residents have brought life to a standstill with protests over the delivery of basic services.

A statement from Ramaphosa's office notes clashes with police and calls for calm and engagement "rather than violence and anarchy." It also urges police to show restraint in the city of about 300,000.

South Africa's next election is in 2019 and the ruling African National Congress party under Ramaphosa is eager to recover from its worst-ever election showing in 2016, in which the ANC lost control of major municipalities.