New York City under Mayor Bill de Blasio is securing nearly 22,000 homes for people who couldn’t otherwise afford to pay the market rent, the most in a quarter century, officials said.

Seated beneath “STILL YOUR CITY” signs in the rapidly gentrifying Brooklyn neighborhood of Williamsburg on Thursday, de Blasio said he wants to keep the city from becoming a playground exclusively for the rich.

“Our job is to make it affordable for every kind of New Yorker — for working people, for middle-class people, for lower-income people, every kind of New Yorker — cuz the magic of New York City is every kind of people in one place, that’s the secret formula,” de Blasio said, touting the number for 2016, a record.

His administration’s signature housing plan, announced in 2014 at the beginning of his mayoralty, calls for the creation or preservation of 200,000 units of below-market-rate housing within a decade.

To achieve that number, de Blasio has refused to grant exceptions to the city’s zoning code for denser building unless the building sets aside a certain number of units for below-market-rate rent.

Under the program, rents are essentially locked in and aimed to be priced about a third of tenants’ incomes to cover a range of circumstances, sliding scales for what poor and middle-class residents can typically afford.

De Blasio’s announcement didn’t placate critics who want more and cheaper housing for New Yorkers who are poor, homeless or otherwise less fortunate.

“At a time of record homelessness in the city, Mayor de Blasio’s self-congratulatory victory lap on affordable housing is offensive and wrong,” said Katie Goldstein, a spokeswoman for the group Real Affordability for All.

De Blasio has countered that he wants to keep the city affordable for all New Yorkers, including the middle class, for whom the city is becoming more and more pricey.