Many lawmakers lost their seats in the elections. Angered by reports of irregularities involving electronic voting machines, members of Parliament passed a law on June 6 to require a manual recount overseen by a panel of judges, rather than the Electoral Commission, which received poor marks for its work.

Members of the victorious coalition led by Mr. Sadr had resisted any recount, expressing concern that the losers might use it to nullify the results.

On Thursday, the Supreme Court ruled that Parliament was within its rights to adopt the law and allow for the recount.

A recount is not expected to significantly change the results, but it could delay the formation of a government by Mr. Sadr, a firebrand militia leader whose forces once battled American troops in Iraq and were implicated in widespread atrocities against civilians.

Mr. Sadr is the coalition’s spiritual leader and was not himself a candidate for office, so he cannot become prime minister. But his coalition made ambitious promises: ending endemic corruption and embarking on reconstruction projects to repair tens of billions of dollars in damages left by the Islamic State, whose fighters have now largely been driven from Iraq.

Hussein al-Adili, a spokesman for the coalition, said on Thursday that it accepted the Supreme Court’s ruling. In a statement, Mr. Adili “called on everyone to abide by the decision to preserve the political process and the sovereignty of law, and to preserve the votes of the electorate and the safety of related measures for the legitimacy of the electoral process.”

Mr. Sadr has begun talks to form a government, but a prime minister and cabinet cannot be selected until the final results of the voting are formally ratified after the recount.

His allies opposed the recount effort, warning of attempts by the losers of the election to steal their victory. The current prime minister, Haider al-Abadi, whose party performed poorly in the election, said that the fraud complaints needed to be taken seriously.

Most of the fraud allegations concern electronic voting machines that were used for the first time in the May balloting.

Mr. Sadr, in a statement, appealed to his supporters to exercise “self-control” and called on them to obey the law, even if they found the Supreme Court’s ruling unconvincing.

He urged the Iraqi judiciary to be “committed to neutrality” with respect to the recount, and he called for a quick completion of the process. He also said that political factions should continue their negotiations with the aim of forming a government.

“There are concerns that the manual recounting and sorting of votes might become a pretext to hold the elections again, encroach on the choices of the electorate and restrict the democratic process and that future voter turnout might be lower,” he warned. He also said that the recount should not be exploited by those who wanted to keep corrupt forces in power.

Hadi al-Amiri, a Shiite political leader with ties to Iran, blamed the government and the electoral commission for the voting problems, attributing the election irregularities to their “failing administration.”

Tariq Harb, a legal expert, called the Supreme Court’s ruling the “constitutionally correct and proper decision.”

There is still the problem of a warehouse storing as many as four million ballots from eastern Baghdad, which burned down days after Parliament filed the legislation for a recount. The departing parliamentary speaker, Salim al-Jabouri, called it arson and said the fire was set to cover up fraud. An electoral official, Saeed Kakei, said that photocopies of the ballots had been made and preserved and could be examined for the recount.

Analysts fear that a long period of uncertainty would be a major setback for Iraq.

“A constitutional vacuum is inevitable,” said Wathiq al-Hashimi, who leads the Al-Nahrain Center for Strategic Studies in Iraq. Parliament is supposed to convene on July 1, but the opening of the chamber might have to be postponed for two or three months because of the recounting and sorting, as well as the time required to hear objections and to certify the vote.

“If the winners turn into losers and their seats are taken away from them, the country would see armed instigation on the streets never before,” Mr. Hashimi predicted. He warned that Kurdish regions in the north, like the oil-rich cities of Kirkuk, and Sunni regions in the West, like Anbar Province, already seem tense.

The United Nations Assistance Mission for Iraq, which supported the election process, said it was ready to continue helping.

Jan Kubis, a Slovak diplomat who is the United Nations secretary general’s special representative for Iraq, said he was confident that the panel of judges would find ways to “work as expeditiously as possible and in a fully transparent way, that will increase public confidence in the election process, enhance its integrity, deliver electoral justice and contribute to the legitimacy of the results of the elections.”

Mr. Kubis called on all parties to respect the law and resolve any disputes peacefully.

Falih Hassan reported from Baghdad, and Sewell Chan from New York.

A version of this article appears in print on , on Page A4 of the New York edition with the headline: Iraqi Court Backs Recount in Last Month’s Elections. Order Reprints | Today’s Paper | Subscribe