The city on Thursday was dismissed from a federal lawsuit alleging that it was negligent in the collapse of a building at the World Trade Center that crumbled hours after the twin towers fell.

Judge Alvin K. Hellerstein dismissed the city as a defendant after concluding that the establishment at 7 World Trade Center of an emergency command post with a backup generator "was a good faith effort undertaken by the city to facilitate civil defense."

"Clearly, this was not routine city business," the judge wrote, explaining that the center was protected by a 1951 law giving municipalities immunity for efforts to provide civil defense.

City lawyer Kenneth A. Becker said the ruling dismisses the last remaining property damage claim against the city arising from the 2001 terrorist attacks.

"This helps permit the city to better plan for events like the Sept. 11 attacks without being subject to liability based on hindsight," he said.

Corporation Counsel Michael A. Cardozo said the ruling was important to cities hit by disasters.

"In light of the different catastrophic emergencies we have seen — both here and in New Orleans — the flexibility required to prepare and respond in innovative ways is critical, and this ruling reaffirms the legislative precedent allowing the planners to do their jobs without being second guessed," he said in a statement.

The case proceeds against the Port Authority of New York and New Jersey, which owns the Trade Center complex, and other defendants.

The lawsuit was brought by the Consolidated Edison Co. of New York and insurance companies, contending that the city had improperly designed and installed a fuel system for the backup electrical system that supported its Office of Emergency Management on the Manhattan building's 23rd floor. The lawsuit seeks unspecified damages.

Con Ed operated below the building an electrical substation that was heavily damaged. The 47-story building, erected in 1987, fell seven hours after fires were started by the collapse of the twin towers.

The plaintiffs noted that the city maintained large tanks of diesel fuel in the building and said the tanks caused the fires to grow out of control.

A Con Ed spokeswoman said the company would have to review the decision before commenting.