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.
The two major parties are also locked in a tight race to control the country’s largest city, Johannesburg.
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.
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”.