RALEIGH, N.C. (AP) — A federal judge ruled Wednesday for the new Constitution Party of North Carolina, blocking a new state law so three of its chosen candidates can run for legislative and county seats in November after all.

The ruling halts enforcement on its candidates of a law the General Assembly finalized in June that prevented people who lost in the May primary election from running for the same office with a new political party in the fall. The law expanded the state's existing "sore-loser" election law that banned candidates who lost primaries from running as an unaffiliated or write-in candidate.

The Constitution Party gained official recognition shortly before the law was implemented and sued last month, arguing it was retroactively applied to them. The party and the three candidates said the law kept them from fully participating in the election and that it violated their right to free speech and association.

U.S. District Judge Louise Flanagan agreed, writing that the retroactive removal was an "erratic execution" of election laws. Flanagan said the Constitution Party demonstrated they had a high likelihood of winning if the case went to trial, and that the party would suffer permanent damage if the law were not temporarily halted.

The preliminary injunction remains in place while the lawsuit continues. Barring a successful appeal, the Constitution Party's candidates who lost in May but were chosen by the party at its convention to run in November — one for a state House seat and two for county commissions — will be on general election ballots.

It wasn't clear Wednesday whether the state board of elections, listed as a defendant in the lawsuit, would appeal. The deadline to finalize ballots is fast approaching. They're supposed to be sent to absentee ballots starting Sept. 7. Republican legislative leaders didn't immediately respond Wednesday to requests for comment on the decision.

The ruling is yet another legal setback for Republican legislators and election-related laws they've passed recently.

A panel of judges on Tuesday blocked questions for two of the six constitutional amendments the legislature approved from being on the November ballot, agreeing with Democratic Gov. Roy Cooper and the state NAACP that the questions were false and misleading.

A state judge last week blocked enforcement of a law that would have prevented a state Supreme Court candidate from having his Republican affiliation next to his name on the ballot because he switched affiliations just before he filed for the seat.

Constitution Party Chairman Al Pisano called Wednesday's ruling a victory, criticizing Republican legislative leadership for changing election laws and "wasting taxpayer dollars on needless lawsuits."

"It's not right for them to change the law when they feel threatened or to change it for partisan advantage after the fact," Pisano said in a statement.

Both the Constitution Party and Green Party became official parties in North Carolina this year following passage of a new law lowering the thresholds they were required to surpass. In early June, the Constitution Party nominated 10 candidates for office by convention. None of the Green Party's candidates were affected by the sore-loser law changes.