The largest rental complex in Manhattan is being sold.

Investment firm Blackstone says it's buying Stuyvesant Town and Peter Cooper Village in Manhattan's East Side for $5.3 billion.

As part of the deal with the city, the firm agreed to preserve 5,000 apartments for affordable housing for the next 20 years.

In the past, apartments at the complex became market-rate once units became vacant or tenants made too much money to qualify for low rent.

"It's a great, great victory for the tenants of Stuy Town and Peter Cooper," said Mayor Bill de Blasio. "We would not be here but for the fact that you wouldn't give up. You believed in protecting housing for the middle class and the working people. You believed that that ideal was not dead in New York City. You did something about it, and that is why today, we celebrate a victory."

Historically, the complex is home to middle-class New Yorkers. Officials for the firm say it intends to continue that tradition.  

The complex was last sold in 2006. It has more than 11,000 apartments in 110 buildings.