YAKIMA, Wash. — At last, the end is in sight for the longest-running and most expensive water rights case in state history.

A unanimous ruling issued Thursday by the Washington State Supreme Court on legal issues involving the Ahtanum Valley, southwest of Yakima, means the case finally will be wrapped up 36 years after the state filed the case to clarify rights to all surface water in the three-county Yakima River Basin.

The Ahtanum is the most complex and the last of 31 individual subareas of the basin yet to have what is known as a conditional final order entered by Yakima County Superior Court. The complexity comes from the fact that two prior adjudications were conducted in the Ahtanum.

“It is the last subbasin and the last proceeding in this long-running case. It is a significant event,” said Alan Reichman, an assistant state attorney general handling the case for the state Department of Ecology. “It is a pretty big step to get to the end of the adjudication.”

Ecology filed the case in 1977, the year in which the Yakima Valley experienced a major water shortage. The filing was meant to sort out all claims to surface water, establishing a priority date and amount for every claimed right.

The case has more than 6,600 defendants, including individual water users, irrigation districts, state agencies, the Yakama Indian Nation, and the federal government.

Issues in the case have been to the state Supreme Court on five occasions.

An estimate of the costs to process the case wasn’t clear on Thursday, but is in the tens of millions of dollars.

In its unanimous ruling, the state’s high court left some work to do for presiding Judge F. James Gavin, who retired from the bench in January but retained the water case, known as the Acquavella case.

Among rulings on seven major issues, the justices remanded part of the case to Gavin for decisions on how many acres could be irrigated on the Yakama Indian Reservation from Ahtanum Creek and whether the tribe can build a storage reservoir to serve those acres.

Once Gavin issues a conditional final order for the Ahtanum basin, the court can move to complete the case and enter a final decree to resolve the case.