Editor's note: This story has been updated throughout.

A Texas Supreme Court ruling has spared the state from having to issue billions of dollars in tax refunds to oil and gas drillers — a prospect that had threatened to shake up the next legislative session.

The justices on Friday sided with Texas Comptroller Glenn Hegar in an arcane tax dispute that the Republican feared could have far-reaching consequences for the state’s budget outlook.

Denying Midland-based driller Southwest Royalties' request for a refund, the court ruled that state law did not exempt its metal pipes, tubing and other equipment used in oil and gas extraction exempt from sales taxes.

The Texas Tribune thanks its sponsors. Become one.

“Southwest did not prove that the equipment for which it sought a tax exemption was used in 'actual manufacturing, processing, or fabricating' of hydrocarbons within the meaning” of the tax code, Justice Phil Johnson wrote in a unanimous opinion that affirmed decisions in lower courts. “Thus, Southwest is not entitled to an exemption from paying sales taxes on purchases of the equipment.”

Though Southwest Royalties, a subsidiary of Clayton Williams Energy, sought to recoup less than $500,000 from purchases between 1997 and 2001, the stakes were far higher.

A Texas loss could have spurred up to $4.4 billion in refund filings for 2017 alone, Hegar’s office estimated, and $500 million each subsequent year that the exemption remained in place.

If accurate, the $4.4 billion transfer would have wiped out the state’s projected budget surplus.

In a statement released after the ruling, Texas Attorney General Ken Paxton praised the court's decision.

"The Comptroller is faithfully executing the law and treating taxpayers fairly, in accordance with the wishes of the Texas Legislature," the statement said. "Bottom line: we saved the State, and taxpayers across the State, over $4 billion."

The Texas Tribune thanks its sponsors. Become one.

Petroleum industry representatives expressed disappointment in the ruling.

“It is undeniable that oil and natural gas exploration and production today is more and more a manufacturing process,” Todd Staples, president of the Texas Oil and Gas Association, said in a statement. “For a healthy oil and natural gas industry, our operators, who compete globally, need equitable tax treatment.”

But some tax attorneys suggested that the ruling was less sweeping than the state may have hoped for and that more tax squabbles could be on the horizon. 

The high-dollar case involved a mix of accounting terms and science.

In oral arguments last March, attorneys on both sides sparred over the mechanics of petroleum extraction and how it related to a tax exemption for goods and services used in the “actual manufacturing, processing, or fabrication of tangible personal property.”

Southwest Royalties argued that the company’s equipment “processes” West Texas crude by separating it into marketable oil and gas. Once the crude is brought up from the ground, it is no longer part of a mineral owner’s estate, its legal team argued.

The state contended that minerals are not “tangible personal property” and that Southwest’s equipment was not necessarily responsible for transforming the crude.

The justices partly agreed.

The Texas Tribune thanks its sponsors. Become one.

“There is no evidence that the equipment acted upon the hydrocarbons to modify or change their characteristics,” Johnson wrote. The changes in the substances were caused not by the application of equipment and materials to them but by the natural pressure and temperature changes,” as oil traveled through the equipment to the surface.

But the justices did not shut the door on exemption claims from all drillers — a sweeping declaration that the state’s attorneys had pushed for.

“Our decision does not turn on the fact that the alleged processing occurred underground as opposed to above ground,” Johnson wrote.

As a result, tax attorneys say, drillers might still attempt to claim exemptions after purchasing somewhat different types of equipment — arguing that its use somehow fits the Texas definition of “processing,” even if Southwest Royalties’ pipes and tubes didn’t.

“I think it’s still open, and I don’t think it’s this huge victory that the comptroller is touting it as,” Zachary Jones, a tax attorney in the Dallas office of Gardere Wynne Sewell LLP, told the Tribune.

In a highly technical statement Friday afternoon, Ryan LLC, the high-powered tax firm that represented Southwest Royalties, also highlighted that nuance.

The result? More legal challenges could follow.

The potential threat to the Texas budget wasn't mentioned in Friday's ruling, but it had drawn debate throughout years of litigation.

Southwest Royalties originally filed its lawsuit in 2009, just before improved technology unleashed a surge of oil production that transformed the U.S. energy landscape. Susan Combs, Hegar’s predecessor, was named in the original challenge.

At a hearing in 2012, Travis County District Judge John Dietz said he would rule in favor of Southwest Royalties, only to later reverse his position in a written decision. 

The driller suggested that a Wall Street Journal article quoting dire warnings from Combs swayed the judge. 

Days before Friday’s ruling, industry groups sought to coax the justices with their own economic analysis.

In a filing Tuesday, the oil and gas association attached a study projecting that a ruling for the industry would cost the state just $2.4 billion in immediate refunds.

Moreover, the study argued, the refund would stimulate production in the struggling industry, carrying millions of dollars of economic benefit.

The study was conducted by the Perryman Group and sponsored by the Texas Association of Business.

Assistant Attorney General Michael Murphy, who argued the case for Texas, dismissed that study as “not an unbiased assessment,” and “advocacy.”

Disclosure: The Texas Oil and Gas Association and The Texas Association of Business have been financial supporters of The Texas Tribune. A complete list of Tribune donors and sponsors can be viewed here

Get The Brief

Never miss a moment in Texas politics with our daily newsletter.