The independent base-closing commission overruled Pentagon plans yesterday to shut two major Air Force bases in South Dakota and New Mexico, setting back Air Force efforts to consolidate its B-1 bomber fleet but preserving thousands of jobs in the states involved.

Commissioners described the votes to save the South Dakota's Ellsworth Air Force Base and New Mexico's Cannon Air Force Base as among the most difficult they had faced in trying to balance the Pentagon's desire to streamline operations with concern about the impact on local economies.

As the commission turned to its final and arguably most politically charged issue -- the reshaping of the Air National Guard -- a note of heightened drama was added to the proceedings by a federal court in Philadelphia. A judge there ruled that the Defense Department lacked authority to dissolve a Pennsylvania Air National Guard division without the governor's approval.

But the commission proceeded anyway. It approved a measure that skirted the ruling by preserving the Guard unit in question while still removing the fighter jets at the installation, Naval Air Station Willow Grove.

Running late in the evening, the commissioners accepted a large part of the Pentagon's plan to remove planes from nearly 30 Guard bases. But they also voted to keep aircraft at some locations the Pentagon had wanted stripped, citing homeland defense and other considerations.

It was by far the most emotional and longest of three days of voting on the Pentagon plan, which aimed to close, reduce or enlarge more than 800 installations to make U.S. forces more efficient and save nearly $50 billion over 20 years. By the end of the day, the commission had ended up preserving this week at least a dozen of the larger bases the Pentagon had wanted shut or shrunk, reducing the projected savings to about $37 million, according to Anthony J. Principi, the commission's chairman.

In the case of Ellsworth, the Defense Department had proposed shifting 24 B-1 bombers there to Texas and consolidating the entire B-1 force at Dyess Air Force Base. But the commission disputed the Pentagon's argument that closure would save $1.8 billion, figuring instead that the result would be a net cost over 20 years of $19 million. The gap reflected a disagreement over how to count 1,520 military and civilian job losses at the base -- one of many disputes the commission has had with the department over the proper accounting of troops whose positions at a base would be eliminated but who themselves would move on to other assignments.

Additionally, the commissioners expressed concern about the devastating economic impact that closure of Ellsworth, the second-largest employer in South Dakota, would have on Rapid City. And they noted little real difference in the facilities and training ranges between the South Dakota base and Dyess.

In Rapid City, people gathered at the Chamber of Commerce cheered and applauded as the 8 to 1 vote was announced.

"Happy days," said Bruce Rampelberg, who headed a task force to save the base. A Pennington County Commission member, Mark Kirkeby, told the Associated Press he had tears in his eyes. "Oh, my God, it's a fantastic day," he said.

The sense of victory was particularly sweet for Sen. John Thune (S.D.), a freshman Republican who unseated Senate Minority Leader Thomas A. Daschle (D-S.D.) last year partly on promises to save Ellsworth.

The question of what to do about Cannon was even more wrenching for the commissioners. They were faced with figures showing that shutting the base would result in a 29 percent loss of local employment for Clovis, a city of 32,000 in eastern New Mexico. Commissioner Samuel K. Skinner said he had awakened at 4 a.m. thinking about what would happen to Clovis if the base were shut. Others noted the base's excellent ramp and airfield facilities, its extensive training ranges and supportive local population.

But Principi called closure "absolutely necessary" if the Pentagon is going to meet its changing needs.

"Painful basing decisions cannot be and should not be avoided or deferred simply because they are difficult," he said. "Postponing necessary decisions simply makes a lot of pain even worse."

Commissioner Lloyd W. "Fig" Newton, a retired general who once oversaw Air Force recruitment and training, offered a compromise that would have transferred a fighter training program to the base. Fellow commissioners rejected that idea, arguing it would not be appropriate for the panel to dictate a specific alternative to the Pentagon. But they settled on another compromise, agreeing to transfer all 60 F-16 fighter jets at Cannon to other bases but ordering that the facility remain open as an "enclave."

The move bought more time for Cannon by directing the Pentagon to try to come up with another mission by the end of 2009. If a new role for the facility cannot be found by then, the action gave the secretary of defense authority to close the base.

New Mexico politicians called the decision a partial victory.

"This is not a total loss," said Sen. Pete V. Domenici (R-N.M.). "We will be putting a lot of pressure on the administration and the secretary of defense to find new missions for Cannon as quickly as possible."

In yesterday's court ruling, U.S. District Judge John R. Padova said Defense Secretary Donald H. Rumsfeld should have obtained consent from Pennsylvania Gov. Edward G. Rendell (D) before moving to deactivate the 111th Fighter Wing of the Pennsylvania Air National Guard. The Pentagon had recommended that the Guard unit, with more than 1,000 jobs, be deactivated and that its aircraft be retired or relocated to other Air National Guard bases.

Several commissioners insisted, however, they were still on firm legal ground. Justice Department lawyers issued an opinion earlier in the month arguing that the base-closure act supersedes federal law requiring gubernatorial consent.

"We think we're on very solid legal ground," Newton said.

But after beginning work on the Guard reshaping plan, the commission suspended deliberations for three hours to try to ensure they would be proceeding properly through a complex set of proposed reshuffling of assets and personnel.

"We're going to be subject to legal challenges," Skinner told reporters. "We've got to dot our i's and cross our t's."

The Pennsylvania case did not involve a challenge to the Pentagon's authority to close Willow Grove, only whether the federal government could deactivate the 111th Fighter Wing based there. But other suits have been filed in Illinois and Tennessee that take issue with the Pentagon's ability to shift Guard aircraft without state approval.

The Air Guard restructuring has upset many state politicians and Guard leaders who complained they had no part in drafting the plan. Unable to compel the Air Force and adjutants general who oversee Guard state units to work out a compromise, the panel fashioned its own.

South Dakotans celebrate the base-closing commission's vote that overruled the Pengaton's decision to close Ellsworth Air Force Base.