The California Supreme Court on Thursday struck down a state law that would have required President Trump to release his tax returns in order to appear on the state’s primary ballot.

Justices in Sacramento said that the law – which required all candidates for president and governor to submit five years’ worth of personal income tax returns in order to be included on primary ballots – was unconstitutional.

“Whatever authority the Legislature may have in defining how presidential primaries are to occur in this state, the challenged sections of the act exceed such authority and are unenforceable,” California Supreme Court Chief Justice Tani Cantil-Sakauye wrote in the opinion.

TRUMP ATTORNEY JAY SEKULOW SAYS CALIFORNIA TRIED TO 'SHRED CONSTITUTION' AFTER COURT RULED IN FAVOR OF PRESIDENT 

Gov. Gavin Newsom, a Democrat, had signed the bill into law in July.

The state Republican Party and Chairwoman Jessica Millan Patterson challenged the bill, while the state has defended the law by arguing tax returns are a simple way for voters to weigh candidates’ financial status.

The ruling by the state’s highest court – which is a rare win for Trump in the Democratically controlled state – comes more than a month-and-a-half after a federal judge temporarily blocked the state law in response to a different lawsuit.

California Secretary of State Alex Padilla appealed the federal judge’s ruling, in a legal dispute that remains ongoing.  The state court’s decision, however, means the tax return requirement cannot be enforced, even if it were found to be constitutional under federal law.

CLICK HERE FOR THE FOX NEWS APP

Jesse Melgar, the governor’s spokeswoman, previously told the Los Angeles Times that Newsom supported an appeal, adding: “States have a legal and moral duty to restore public confidence in government and ensure leaders seeking the highest offices meet minimal standards.”

The deadline for submitting tax returns to get on the primary ballot under the bill, though, is next week.

Under California’s so-called jungle primary system, all candidates, regardless of party, vie for the same elected office and the top two vote-getters move on to the general election. Since it was implemented in California in 2010, this system has often ensured a Democrat-vs.-Democrat general election battle in all but California’s most conservative areas.

Fox News’ Danielle Wallace and The Associated Press contributed to this report.