After the declaration, the president's supporters took to the streets of Tehran, waving Iranian flags and honking car horns.
"Where are the greens? In a mousehole," some of them said, referring to the campaign colours of Mousavi, whose supporters held mass rallies in recent weeks.
Mousavi had claimed victory just moments after polls closed on Friday.
"In line with the information we have received, I am the winner of this election by a substantial margin," he said. "We expect to celebrate with people soon."
But with the majority of votes counted according to Kamran Daneshjoo, chairman of the electoral commission at the interior ministry, the incumbent president had taken a seemingly unassailable lead.
The two other candidates up for election - Mohsen Rezai, a former commander of Iran's Revolutionary Guard, and Mehdi Karroubi, an ex-parliament speaker - were set to finish a distant third and fourth.
Mousavi alleged there had been irregularities in the voting, including a shortage of ballot papers.
He also accused the authorities of blocking text messaging, which his campaign has used to reach young voters.
Richard Dalton, a former British ambassador to Iran, told Al Jazeera: "There has been fraud alleged by the losing candidates in other Iranian elections and there has been good evidence produced that [it] actually happened.
"So one can't rule it out in this case. What is more important in the early stages is people's perceptions. If people perceive they were robbed, that will stir up political passion in what is still a volatile country."
Al Jazeera's Alireza Ronaghi, reporting from Tehran, said the blocking of text messages had been announced by the ministry of communication.
"We haven't heard what the reason for this is, but we know that Ahmadinejad's campaigners and supporters have accused the reformists of trying to plot riots and acts of unrest after the election," he said.
"We have also heard that some of the newspapers have been given notices to change their editorials or their main headlines."
Scuffles broke out between police and chanting Mousavi supporters in a Tehran square early on Saturday, witnesses said. Police said they have increased security across the capital to prevent any trouble.