Zambian President Edgar Lungu narrowly won re-election on Monday in a vote his main rival said was rigged.
Hakainde Hichilema's United Party for National Development (UPND) said it would appeal the result at the Constitutional Court, accusing election officials of fraud during the count which began after voting ended on Thursday.
Lungu faced a tough challenge from Hichilema in a campaign to rule over Africa's second-largest copper producer which has suffered an economic slump due to depressed commodity prices.
Lungu, who narrowly beat Hichilema in a vote last year to replace late president Michael Sata, won 50.35 percent of the vote against 47.63 for his opponent, the Election Commission of Zambia (ECZ) said on Monday.
Hundreds of Lungu's supporters, most of them young men draped in the regalia of the ruling Patriotic Front (PF), took to the streets, chanting slogans and singing, while drivers hooted their car horns in celebration.
"I'm happy that Edgar Lungu can continue to be president because I see a good future with him. I want him to create jobs for young people," said 15-year-old Zegu Kaunda who said he wanted to study law like Lungu.
But student Harrison Simenda, 24, who supports Hichilema, popularly known as HH, said: "They have stolen this election from HH but they will not enjoy it because I see very tough times ahead for our economy."
UPND party lawyer Jack Mwiimbu told reporters: "We have evidence to the effect that the votes for Hakainde Hichilema have been deliberately reduced in collusion with the Election Commission of Zambia."
He said the party was confident the Constitutional Court would declare the election result invalid.
The ruling party and the electoral commission have rejected the UPND's charge.
Police said officers were sent to quell rioting by Hichilema's supporters in the south of the country after the result was announced.
The election was fought around the issues of rising unemployment, mine closures, power shortages and soaring food prices which Hichilema, an economist and businessman, blamed on Lungu's mismanagement.
But Lungu, whose government has been talking to the International Monetary Fund about financial aid to help plug its budget deficit, said he was doing his best to wean the economy off its over-reliance on copper.
"You can trust the government of President Edgar Lungu. We mean well and we shall not betray the people's trust," PF secretary-general Davis Chama said.
The election dispute, which could blight Zambia's reputation as one of the most stable democracies in Africa, could damage negotiations with the IMF, Capital Economics Africa analyst John Ashbourne said.
"The re-election of President Lungu, who had promised to drive a hard bargain with the IMF, could slow negotiations on a deal with the fund," he said.
The UPND said on Saturday data from its own parallel count showed Hichilema beating Lungu "with a clear margin" with about 80 percent of votes counted. Monday's result means Hichilema has now lost five presidential elections.
All parties had access to the raw voting data, in which Zambians also chose members of parliament, mayors and local councillors, faster than the national commission.