South Africa's governing African National Congress has been defeated by the opposition Democratic Alliance in local polls in the capital Pretoria.
The DA took 43% of the vote compared with the ANC's 41% in Tshwane, the municipality that includes Pretoria.
The DA will need to form a coalition in order to secure control there.
In the country's largest city, Johannesburg, the ANC beat the DA but fell short of an outright majority, with 44% of the vote.
The ANC has also lost Nelson Mandela Bay metropolitan area in the Eastern Cape, which includes Port Elizabeth, to the DA.
It is the ANC's worst electoral performance since it was elected to power at the end of apartheid and the replacement of white minority rule by democracy in 1994, and the first time since then that it has lost control of the capital.
The DA has won 93 seats in Tshwane while the ANC is second with 89 seats in the 214-seat municipal council.
Observers say a host of corruption scandals and internal party squabbles are to blame for the ANC's decline.
The South African economy has stagnated since 2008's global financial crisis, and the country has one of the highest rates of economic inequality in the world.
Revelations that upgrades to President Jacob Zuma's private home were funded with $20m of public money caused an outcry. The Constitutional Court recently instructed Mr Zuma to reimburse the state $507,000.
ANC's influence in decline: Milton Nkosi, BBC News, South Africa
The municipal election result is probably the biggest wake-up call the governing ANC has received since it ushered in democracy in South Africa in 1994.
Clearly the ANC still commands huge support across the country but that support is waning. It can no longer take it for granted that the black majority will blindly follow it.
A good example is in the Nelson Mandela Bay municipality, won by the DA, which has a rich history of anti-apartheid struggle. Its new DA mayor is Athol Trollip, who is white.
Twenty-two years after the end of apartheid, black people are now voting on issues and not on race. Mr Trollip, who speaks fluent Xhosa, would not be where he is if the vast majority of black people had not voted for him.
The party of late President Mandela, the icon of the struggle against apartheid, still commands strong support with about 54% of the national vote.
The DA has received about 27%, while the radical Economic Freedom Fighters party - contesting local elections for the first time - has taken about 8%.
The DA's leader, 36-year-old Mmusi Maimane, told reporters: "For far too long, the ANC has governed South Africa with absolute impunity."
He added that the idea that his party - which has its roots in the non-ANC opposition to apartheid - was a white one had been "completely shattered".
The ANC said it would "reflect and introspect where our support has dropped".
In a brief address before the final results were announced, 74-year-old President Zuma praised the conduct of a vote he called largely peaceful, free and fair.
"Our democracy is maturing," he said. "Let us get back to work and build our country together."