SACRAMENTO — After a yearlong royal rumble between the San Francisco 49ers, local schools, the Brown administration and others, a judge on Wednesday ruled that South Bay school officials were wrong last year to yank $30 million in disputed tax funds from the team’s new stadium.

Sacramento Superior Court Judge Allen Sumner said in a nine-page tentative ruling that he could not immediately award the funds to the 49ers, but he appeared to leave little recourse but to make sure the Niners eventually receive the money one way or another. The team may have to wait until as late as 2016 to receive the cash, however, the judge said.

K-12 schools in Santa Clara County argued they needed the money to prevent further classroom cutbacks while Gov. Jerry Brown’s finance team tried using the funds to help balance the state budget.

But Sumner ruled that Santa Clara voters and city officials had specifically earmarked the funds for the new stadium being built in the city — and outside groups had no legal right to take it away.

“He supported both the city’s and 49ers’ point of view, as well as the citizens’,” said Santa Clara Mayor Jamie Matthews. “I’m exceedingly pleased that the judge validated our position.”

The losing sides will appeal during a hearing Friday afternoon, which will conclude a contentious court case that began when the 49ers sued to reclaim the money last June.

The 49ers declined to comment, citing the ongoing court case. Members of the other parties involved in the case and their attorneys did not return calls seeking comment.

Although the fight over the money has been tenacious, the stakes have lowered in the past year as the groups involved saw their finances improve.

The 49ers say the case will not affect construction of the $1.2 billion stadium, which is more than one-third complete and set to open in 2014 on the backs of $1 billion in bank loans and NFL financing. Local schools were essentially made whole after state voters in November approved Proposition 30, a tax hike that offset the revenues that schools were hoping to win from the 49ers. Proposition 30 also helped balance the state’s nearly $100 billion budget, to which tens of millions of dollars is a drop in the bucket.

The funding saga, which has seen its share of twists and turns before this week’s finale, was born in 2010, when Santa Clara voters approved a stadium measure that called for the team to get $40 million in redevelopment tax funds. But after the team was paid $10 million of its share, the state abolished redevelopment agencies in 2011, calling into question the fate of all redevelopment property tax revenues.

A new board of local school superintendents, elected leaders and finance officials, charged with overseeing old redevelopment projects, voted in June to pull the remaining $30 million and give it to local schools and other Santa Clara County agencies. They argued that cash-strapped classrooms needed the money more than wealthy sports executives.

After a public spat that pitted football fans against parents, both sides in August agreed to a settlement that would have seen the schools get about half the money they wanted while the Niners would wait a few extra years to get their full share.

But in October, the California Department of Finance — the highest bureaucratic referee on redevelopment funding fights — rejected that deal, hoping to route the money to the county through the state’s general fund, which would help reduce the budget deficit. So the state was sued as well, and the case was left in the judge’s hands while the money was frozen under court order.

The key legal question is simple: Did the 49ers and Santa Clara sign the stadium funding deal before Brown proposed eliminating redevelopment — making it legit — or did the stadium contract come after, which might have put the money up for grabs?

The initial stadium funding contract and public vote certifying it were clearly signed before Brown proposed scrapping redevelopment. But groups such as the Oversight Board, Santa Clara County Finance Director Vinod Sharma and California Finance Director Ana Matosantos argued that the final, binding deal — and the settlement proposed in August — did not come until well after redevelopment was scrapped.

“Do those contracts survive dissolution of the redevelopment agencies?” Sumner writes in his ruling. “The court concludes they do.”

But instead of awarding the team the money, he kicked the issue back to the oversight board “to take further action consistent with this ruling,” keeping in mind that they were wrong the first time around in voting to make the stadium funding contracts invalid. That board will meet next on April 12.

Contact Mike Rosenberg at 408-920-5705. Follow him at Twitter.com/rosenbergmerc.