A federal judge has stopped the hand recount of nearly 5 million ballots in Michigan, a decision that seems to secure Donald Trump’s narrow victory in the traditionally blue state.

U.S. District Judge Mark Goldsmith, who effectively ordered the recount to begin Monday, sided with a state appeals court Wednesday in halting the effort, ABC News reported.

On Tuesday, a Michigan appeals court ruled 3-0 that Green Party candidate Jill Stein should not have been allowed to demand a recount because she is not an “aggrieved candidate.” Goldsmith, after hearing arguments from the state Republican Party and GOP attorney general, agreed.

“Because there is no basis for this court to ignore the Michigan court’s ruling and make an independent judgment regarding what the Michigan Legislature intended by the term ‘aggrieved,’ plaintiffs have not shown an entitlement to a recount,” Goldsmith said.

The Stein campaign’s lead lawyers in Michigan said they were “deeply disappointed” with the ruling.

“The history of this country is one where federal courts step in to protect the constitutional voting rights of all Americans, especially when they are under attack in the states,” Hayley Horowitz and Jessica Clarke said in a statement.

“Well today, they are under brutal attack.”

They called the president-elect’s efforts to suppress the vote recount a “stunning about-face, even by Trump’s own standards.”

“Recounts are not about politics or parties; they are about our democracy,” the statement said.

“By stopping the recount in Michigan, Trump and Michigan Republicans are explicitly stripping the constitutional rights of Michigan voters straight from under them. Worse, they are continuing to undermine confidence in the American political system by denying voters a chance to be reassured that the election results were accurate.”

The statement said the campaign will continue to fight to protect the voting rights of all Americans. In its next step, the campaign will “seek immediate relief in Michigan’s Supreme Court to ensure the recount that is already underway in all Michigan counties continues.”

“We need this recount to ensure the fairness, accuracy and integrity of the vote.”

Michigan’s attorney general Bill Schuette lauded the ruling late Wednesday in a statement on Facebook, calling it a “huge victory for Michigan taxpayers and the rule of law.”

Stein earned just 1 percent of the vote in Michigan, where Trump won narrowly over Hillary Clinton.

An attorney had urged the judge not to allow the $5 million cost of the recount to be left to the taxpayers, the Detroit Free Press reported.

President-elect Trump and his allies had filed a lawsuit to stop the recount in the state last week, along with legal efforts to block recounts in Pennsylvania and Wisconsin, where Stein is also questioning results.

A court order filed Saturday called the Pennsylvania statewide recount “closed” after the Green Party was not able to come up with a $1 million bond payment required prior to a scheduled hearing.

Stein is now trying to force a recount through a federal lawsuit. But she was dealt a blow on that front Wednesday when a judge denied a full forensic analysis of Philadelphia’s voting machines and their software, Reuters reported.

As of Wednesday evening, Stein’s website showed she had raised more than $7 million toward the recount effort.

Trump had previously called Stein’s push for a recount a “scam” and said she was raising money for her own campaign.

“This is a scam by the Green Party for an election that has already been conceded, and the results of this election should be respected instead of being challenged and abused, which is exactly what Jill Stein is doing,” Trump said in a statement in November.

Stein said on Wednesday the country deserves to have confidence in its voting system without the recount process being so arduous.

“A recount where we have to raise $9- or $10 million dollars in order to have confidence in our votes is insane,” she said in a Facebook Live, talking with a member of the Green Party of Michigan.

“A recount system where we have to jump through administrative hoops and go into court is absolutely crazy.”

Stein also blasted the president-elect for his strong opposition to the recount efforts, citing Trump’s comments during his presidential campaign that the election was rigged.

“Donald Trump and his cronies are doing everything possible to try to stop this exercise in our democracy, this effort to validate our vote,” Stein said.

“Such that it suggests that Donald Trump is very afraid that his vote is not valid, that he’s very afraid of this process of democracy.”