This is the story of a housing war, and an unexpected victory for some of the city's most maligned activists.

On one side were the Lower East Side's squatters, ordinary people who illegally occupied some of the city's most decrepit abandoned buildings. Against them stood the city of New York, which through three mayors was ready to use its full firepower to get them out. The story of their conflicts is one of pitched battles, paramilitary assaults, and incredible bravery and risk. And for more than 200 squatters who toughed it out and are still in their homes, it's now a story with a happy ending.

In the spring of 1989, the squatters of Umbrella House barricaded themselves in their building when the city's demolition crew arrived at the foot of Avenue C to tear it down. As the wrecking ball started to swing, biting into the vacant tenement next door and coming ever closer to their homes, they stationed themselves in their windows and defied the police to take them out.

"I put a big sign on my window that said, 'I'm willing to die for my home, how about you?,'" recalls Umbrella House squatter Siobhan Meow. "And I meant it, I really meant it. I wasn't fucking around. Because I had nothing other than that building."

During a three-day standoff, the police blocked off Avenue C between East 2nd and 3rd streets while the squatters bricked up their front door and ducked in and out through back alleys. They brought in water from a fire hydrant around the corner. They used buckets for toilets, scurrying out of their building under cover of darkness to empty the waste into city sewers. They took showers outdoors, in the runoff from rainstorms. Because the city Department of Housing Preservation and Development (HPD) had ripped out most of the interior staircase, they used the rear fire escape as stairs.

Compared with what went down at other squats, this was a minor skirmish. On May 30, 1995, hundreds of heavily armed NYPD riot cops invaded the East Village in an armored personnel carrier, evicting squatters from 541 and 545 East 13th Street and arresting 31. The battles were not confined to Manhattan: Between 1990 and 1995, the city used every weapon at its disposal--police officers, firemen, EMTs, housing cops--to evict hundreds of squatters, mostly low-income Latino factory workers and their families, from about 200 South Bronx apartments.

Three successive mayors--Koch, Dinkins and Giuliani--treated squatters as if they were more dangerous than violent criminals. The hardball tactics, along with changes in the housing market, seemed to spell the end of squatting in the city. By the late 1990s, there were only about a couple of hundred squatters left in Manhattan, most of them in a dozen buildings on the Lower East Side.

But now, 11 of the Lower East Side's 12 remaining squats are about to sign a deal with their old archenemy. The Loisaida squats, last bastion of illegal occupancy, are becoming official, and soon the squatters will own their homes. For the past three years, the squatters have been quietly working to buy their apartment houses from the city and turn them into low-income cooperatives. And after decades of arguing that legalizing squats would encourage squatters to invade buildings everywhere, the city has agreed to do just that.

In late August 1999, the Lower East Side's remaining squatters began secret negotiations with the Giuliani administration. Much like shuttle diplomacy in the Middle East, they never talked directly; instead, they communicated through an intermediary, the Urban Homesteading Assistance Board (UHAB), a local nonprofit that helps tenants take over and manage their buildings. After much discussion, they cut their own version of the Camp David accords. The squatters have agreed to tame their anarchist tendencies and become legal, hiring architects to bring their homegrown rehabs up to code. The city has agreed to sell the buildings to UHAB, which will take responsibility for them during the renovations and then sell them back to the tenants as low-income cooperatives.

The deal, hammered out during the last days of the Giuliani administration, was delayed after September 11. But Mayor Michael Bloomberg's staffers have honored the basic framework, and on June 26, the deal to save the squats passed the City Council. Several weeks later, Bloomberg signed off on it.

No one, not even those close to the deal, knows for sure why the city finally agreed to end this two-decade standoff. HPD Commissioner Jerilyn Perine declined repeated requests for an interview, issuing a written statement that said, "HPD is continuing its longstanding policy of conveying our in rem properties to quality, non-profit developers. We are confident that UHAB will make sure the buildings are rehabilitated and become safe, decent and affordable housing for local residents."

But the lengthy, bitter squatter battles of the past suggest what the city's reasons might be. Informed observers speculate that since most of the remaining squatter buildings are stable and well-run, they would resist attempts at eviction and get sympathetic press coverage in the process. Since at least one of the squats agreed to drop ongoing litigation, the deal has also saved the city considerable court costs--another one of Mayor Bloomberg's goals.

For the squatters, going legal means abandoning their outsider status, which has been both an ethical stand and a source of pride. "I'm kind of torn on that, because, well, I'm kinda proud of beating the system," admits John Wagner, who has lived at Serenity House on East 9th Street since the early 1990s. One friend of Wagner's, who used to live in the squat and thinks that the squatters are selling out, sends him letters addressed to "house thief John Wagner."

But going legit after decades of extralegal occupation is less of a contradiction than it might seem. While outsiders, city bureaucrats and even some housing activists regard them as middle-class anarchist scofflaws, the squatters themselves invoke the more practical notion of old-fashioned sweat equity ownership. Their longtime defiance may have been political, but it was also practical. They wanted to keep their homes. For Wagner and the others, legalizing the squats is just another way to do that.

"The whole issue of taking over vacant space and using it is revolutionary, according to the establishment," said Hafid Lalaoui--who lived in many East Village squats over the years, most recently at Bullet Space on East 3rd Street--as he basks in the afternoon shade on Avenue C. "But it's not stealing. It's recycling and transforming and building community. We were not anarchists, not anti-establishment. We were struggling to survive--period."