Stuyvesant Town and Peter Cooper Village -- Manhattan's largest rental complex and one of its remaining middle-class bastions -- is being sold for $5.3 billion to a developer that pledges to keep nearly half of the 11,241 apartments below market rates for 20 years, city and state officials announced yesterday.

Mayor Bill de Blasio, appearing alongside tenant representatives, called the deal a "great, great victory" for residents who have fought court cases, eviction notices and rent increases since a 2006 sale of the complex by MetLife to Tishman Speyer Properties.

"Your future is now secure," de Blasio said at a news conference in the 80-acre, 110-building complex. "This community will continue to be a community for all."

Jonathan Gray, global head of real estate for the Blackstone Group, which is acquiring Stuy Town-Peter Cooper, sought to similarly alleviate fears.

"The uncertainty and turmoil that this complex has endured since the financial crisis is definitively over," he said.

Tishman Speyer gave up the complex after a debt default amid recession in 2010, and it is now owned by a creditors group, CWCapital Asset Management. MetLife, with city help, built the complex in the 1940s as a haven for World War II veterans.

Under the regulatory agreement worked out for the sale, 5,000 units will remain under market rate, with 90 percent for households making up to $128,210 and 10 percent for those making up to $62,150.

A two-bedroom apartment would rent for about $3,200 under the cap. Gray said market-rate units average $4,300.

In return for Blackstone's concession on rent, the city will grant a mortgage recording tax exemption of $75 million and real property transfer tax equivalent of $144 million, said Alicia Glen, deputy mayor for housing and economic development.

Additionally, according to the agreement, the 1,400 units that had been set for conversion to luxury rentals in 2020 will have five more years of protections from "extreme rent increases," said City Councilman Daniel Garodnick, a Democrat who lives in the complex.

The deal with Blackstone, which is working with Canadian pension fund manager IvanhoƩ Cambridge, was executed Monday and is to close by the end of the year, Gray said.

Susan Steinberg, president of Stuy Town's tenants association, called the agreement a "solid outcome." She said her group will continue to advocate for affordability.

"In the meantime, this deal is a win for our community," Steinberg said.

Brandon Muir, executive director of Reclaim New York Center for Government Reform and Accountability, which advocates free-market policies, said the deal is "not scalable" to the rest of the city. The city's housing squeeze can only be solved by the production of more units, he said.

"It's essentially paid for on the backs of taxpayers, most of whom do not live in Stuy Town," Muir said.