Opposition leader Michael Sata has won Zambia's presidential election after two days of vote counting following a tight race with incumbent Rupiah Banda.
Mr Sata was declared winner by Chief Justice Ernest Sakala after polling 43% of the vote with just seven constituencies left to be counted.
The election had been marred by riots in Zambia's northern mining region.
The anger had been prompted by a ban on the media announcing results not verified by the electoral commission.
The electoral commission said it had taken the step after its website was hacked to falsely record a landslide for 74-year-old Mr Sata.
Mr Banda's Movement for Multiparty Democracy (MMD) has ruled Zambia for 20 years and this was the fourth time Patriotic Front (PF) leader Mr Sata had run for the presidency.
He lost the last election, in 2008, by just 35,000 votes which sparked rioting by some opposition supporters in the party's urban strongholds.
However, they were in jubilant mood after the victory announcement early on Friday morning. The BBC's Louise Redvers, in the capital Lusaka, said parties were expected to continue into the night.
Mr Sata, who reportedly used to sweep floors at London's Victoria Station, has had a lengthy career in politics. He served as an MMD minister for local government, labour and social security, and health before quitting in 2001.
Known as "King Cobra" for his venomous tongue, foreign mining firms - often from China - have frequently been the target of his criticism about labour conditions.
While the party has disputed media reports it is anti-Chinese, it is likely to shake up the way contracts are awarded, our correspondent said.
Meanwhile, international election observers criticised the MMD for abusing state resources during its campaign and noted serious media bias on the part of the state broadcaster.
However, the PF's promises of more jobs and better education appear to have won over the electorate.