A unanimous Supreme Court on Thursday overturned the convictions of two of former New Jersey governor Chris Christie’s political allies in the “Bridgegate” case, saying the federal government went too far in prosecuting them for retaliating against a political rival.

The former allies, Bridget Kelly and William E. Baroni Jr., were accused of taking part in a 2013 plot to back up traffic on the George Washington Bridge, the nation’s busiest. The idea was to punish the Democratic mayor of Fort Lee, N.J., for not endorsing Republican Christie’s reelection bid.

Traffic stalled in Fort Lee for four days — but revelation of the plan proved dire to Christie’s subsequent presidential campaign, although he said he had no knowledge of it, and the episode created lasting animosities.

President Trump tweeted Thursday that the court’s decision was a “complete and total exoneration” of Christie and his former associates on “the Obama DOJ Scam referred to as ‘Bridgegate.’ ”

In fact, Justice Elena Kagan, writing for the court, was unsparing in her criticism of the scheme. But she said the goal of Kelly, Christie’s former deputy chief of staff, and Baroni, formerly deputy executive director of the Port Authority of New York and New Jersey, was not to secure money or property, which is a requirement of the federal statute under which they were convicted.

“Baroni and Kelly used deception to reduce Fort Lee’s access lanes to the George Washington Bridge — and thereby jeopardized the safety of the town’s residents,” Kagan wrote.

“But not every corrupt act by state or local officials is a federal crime. Because the scheme here did not aim to obtain money or property, Baroni and Kelly could not have violated the federal-program fraud or wire fraud laws.”

The decision was the latest in which the Supreme Court has reined in federal prosecutors who pursued criminal convictions of political conduct. Kagan wrote that the outcome was dictated by the court’s previous decisions and did not require a new interpretation of the law.

Christie responded to the decision with a broadside against former U.S. Attorney Paul J. Fishman, whom the former governor said “was determined to damage the reputations of as many members of our administration as he could.”

“Despite being repeatedly told by numerous respected members of the bar during the investigation that he was inventing a federal crime, Paul Fishman proceeded, motivated by political partisanship and blind ambition that cost the taxpayers millions in legal fees and changed the course of history,” Christie said. “Worst of all, Fishman allowed Bill Baroni to go to jail for federal crimes he invented.”

Christie has long viewed the 16-month investigation and the convictions of his allies as a key reason that his bid for the presidency fizzled.

Fishman said he was disappointed by the court’s ruling but noted the court’s recitation of the facts of the case.

Prosecutors and law enforcement officers “uncovered and exposed those responsible for their conduct, their motivation to assist Chris Christie’s reelection and the many lies they told to cover their tracks,” Fishman said in a statement.

Kelly asked the Supreme Court to take the case last year, when she was facing a 13-month prison sentence. Baroni had begun serving his 18-month sentence before being released on bail.

In a statement, Kelly said: “Today, the court gave me back my name and began to reverse the six-and-a-half-year nightmare that has become my life. … While this may finally have made this case right for me, it does not absolve those who should have truly been held accountable.”

Baroni’s attorney Michael A. Levy, said in a statement that Baroni has always maintained that he did not commit a crime. “Although the process of getting to this day has been an ordeal, Bill is heartened that the system ultimately worked, even as he recognizes how often it fails others who are less fortunate,” Levy said.

The scheme involved shutting down bridge lanes relied upon by Fort Lee commuters. The idea behind it was punishment for Mayor Mark Sokolich, who had decided not to endorse Christie, then running for reelection

“Time for some traffic problems in Fort Lee,” Kelly wrote in an email to officials at the port authority, which operates the bridge.

Kagan called it “an admirably concise email,” and said Kelly and others “merrily” kept the lane realignment in place for four days.

Kagan wrote that the consequences were more than a prank. “School buses stood in place for hours” on the first day, she wrote. “An ambulance struggled to reach the victim of a heart attack; police had trouble responding to a report of a missing child.”

Still, Kagan continued, that does not add up to what federal prosecutors had charged.

“The evidence the jury heard no doubt shows wrongdoing — deception, corruption, abuse of power. But the federal fraud statutes at issue do not criminalize all such conduct,” she wrote. “Under settled precedent, the officials could violate those laws only if an object of their dishonesty was to obtain the Port Authority’s money or property.”

Instead, “the realignment of the toll lanes was an exercise of regulatory power — something this court has already held fails to meet the statutes’ property requirement.”

The ruling is part of a pattern in which the court has expressed skepticism about prosecuting political scandals that do not have direct evidence of bribes or kickbacks.

“The message delivered in this ruling is that hardball politics, even instances in which corruption and abuse of power may be clear, cannot be turned into a federal crime unless the public official’s dishonesty was aimed at obtaining money or property,” said Robert A. Mintz, a Newark lawyer and former federal prosecutor. “A purely political motive is simply not enough to criminalize even deceitful political behavior.”

The case is Kelly v. U.S.

Josh Dawsey and Devlin Barrett contributed to this report.