President Emmerson Mnangagwa's win in last month's polls has been upheld by Zimbabwe's Constitutional Court.
The opposition MDC Alliance had brought the legal challenge saying the vote was marred by "mammoth theft and fraud", but this was rejected by the court.
Delivering the verdict, Chief Justice Luke Malaba called allegations of tampering "bold and unsubstantiated".
It was Zimbabwe's first election since long-time leader Robert Mugabe was ousted from power last year.
Two days after the vote, at least six people were killed in clashes between the army and MDC Alliance supporters, who alleged that party leader Nelson Chamisa had been robbed of victory.
Ahead of the court ruling, the streets around the courthouse in the capital, Harare, were cordoned off by security forces.
The BBC's Shignai Nyoka in Harare says that the city's roads are mostly empty.
What did the judges say?
In a unanimous judgement, the nine judges ruled against the opposition's petition because they said it did not include sufficient evidence.
"The best evidence would have been the contents of the ballot boxes themselves," Chief Justice Malaba said.
He also said that if the opposition had requested a re-count of the vote it would have provided "a clear and indisputable picture of the outcome of the election".
Chief Justice Malaba then dismissed as "startling" the MDC Alliance's claim that an official revision of the vote share was itself proof of irregularities.
President Emmerson Mnangagwa narrowly avoided a second-round run-off when he took 50.7% of the vote. Zec, the electoral commission, had revised this figure from the 50.8% it originally released.
Chief Justice Malaba said the body had "complied with prescribed procedures" when it announced the change.
What were the allegations?
Central to the opposition's legal challenge was their claim that the recorded number of votes had been doctored to hand President Mnangagwa victory.
In Zimbabwe's voting system, a candidate can win in the first round and avoid a second-round run-off if he or she secures more than 50% of the vote.
The opposition alleged that Mr Mnangagwa's 50.7% vote share - which was just 30,000 more votes than the minimum needed for outright victory - was suspicious.
It says that when the votes were counted, 40,000 more presidential ballots were found than parliamentary ones.
International election observers, who were allowed into Zimbabwe for the first time in 16 years, largely praised the conduct of the polls.
However, European Union observers were more cautious, stating that all parties should accept the verdict but also suggesting that President Mnangagwa had benefited from an "un-level playing field".
'A deeply divided nation'
Analysis - Shingai Nyoka, BBC News, Harare
The uncertainty that has hung over this nation for weeks has now finally been resolved by the Constitutional Court.
Mr Mnangagwa is expected to be inaugurated within 48 hours.
And while he has received legitimacy from the courts, he still faces an uphill task of uniting a deeply divided nation and winning over a popular opposition leader who refuses to accept his victory.
What has President Mnangagwa said?
The president has tweeted that he was "not surprised" by the Constitutional Court's ruling.
He said he was calling "for peace and unity above all" and that his "door is open" to his opposition rival who brought the legal challenge.
I once again reiterate my call for peace and unity above all. Nelson Chamisa, my door is open and my arms are outstretched, we are one nation, and we must put our nation first. Let us all now put our differences behind us. It is time to move forward together. (4/4)— President of Zimbabwe (@edmnangagwa) August 24, 2018
But his tweets included criticism of the opposition MDC Alliance, accusing it of instigating "wholly unnecessary violent protests" after the 30 July polls.
A group of 27 opposition activists have been charged with inciting public violence but maintain their innocence.
The US has criticised the detention of, and "abuses" against, opposition supporters, in particular expressing concern for the "physical safety" of key opposition figure Tendai Biti who was arrested in connection with the post-election violence.
What has the MDC Alliance said?
The opposition party has vowed to dispute the ruling even though it says it "respect[s] the verdict of the courts".
"We shall doggedly pursue all constitutionally permissible avenues to ensure that the sovereign will of the people is protected and guaranteed," the MDC Alliance tweeted.
Our unstinting belief in the rule of law means we shall not only respect the verdict of the Bench but we shall also doggedly pursue all constitutionally permissible avenues to ensure that the sovereign will of the people is protected and guaranteed.— MDC Zimbabwe (@mdczimbabwe) August 24, 2018
The party hinted that justice had failed, saying "the sombre mood in the country in the wake of today's court verdict is in itself a telling statement".