A federal judge has ordered the reinstatement of New York’s June 23 presidential primary, ruling that its cancelation was a violation of voters’ constitutional rights.

The decision Tuesday came as a result of a lawsuit filed against the state Board of Elections by former Democratic presidential candidate Andrew Yang and several Yang delegate candidates.

The board on April 27 removed Yang, Vermont Sen. Bernie Sanders, and other presidential candidates who had dropped out of the race from the New York ballot and cancelled the primary race.

Commissioners said they did so in large part to protect the health and safety of voters and elections workers during the COVID-19 crisis.

The move made former Vice President Joe Biden the effective winner of the state primary.

But U.S. District Judge Analisa Torres ruled in favor of the plaintiffs calling for the primary race to be restored.

Her 30-page decision read in part: “Protecting the public from the spread of COVID-19 is an important state interest. But the Court is not convinced that canceling the presidential primary would meaningfully advance that interest—at least not to the degree as would justify the burdensome impingement on Plaintiffs’ and Plaintiff-Intervenors’ rights.”

A spokesman for the state Board of Elections declined to comment, but said the board’s lawyers are reviewing the decision. He did not say whether the board planned to appeal Torres’s decision.

An attorney for Yang and the plaintiffs noted that Yang, Sanders, and other former candidates had not asked to be removed from the ballot and added that the Democratic National Committee also didn’t ask for the decision.

"Now, New Yorkers have stood up after being denied their right to vote and justice has prevailed. We are all looking forward to voting on June 23 and are grateful to the court,” attorney Jeff Kurzon said.

Yang in a tweet wrote: “I’m glad that a federal judge agreed that depriving millions of New Yorkers of the right to vote was wrong. I hope that the New York Board of Elections takes from this ruling a newfound appreciation of their role in safeguarding our democracy.”

A plaintiff in the case, Manhattan congressional candidate Jonathan Herzog, told NY1 that the decision was a “victory for democracy” and said New York voters could exercise their right to vote while protecting their health by applying for absentee ballots.

Sanders, his campaign, and his supporters had made clear that they wished for him to remain on the ballot — despite his April 8 exit from the race and eventual endorsement of Biden. They said he wanted to continue collecting delegates in order to influence the Democratic Party platform at the national nominating convention.

In canceling the primary race, State Board of Elections Co-Chair Douglas Kellner had said Sanders’s supporters effectively sought a “beauty contest” in the primary, considering that the Vermont senator was no longer in the race.

Kellner had told NY1 that the Yang suit had “no mention at all of the New York law that provides for removal from the ballot of a presidential candidate who suspends his or her campaign.”

Kellner also asked had Torres, the judge in the case, for an expedited decision so that New York could avoid the last-minute chaos caused by court rulings in the Wisconsin primary.

Several congressional and legislative primaries are also set to take place June 23 in New York.