A Queens landlord has agreed to fork over almost $1.2 million to settle a long-running lawsuit alleging it had a blanket policy of denying units to ex-cons.

The Fortune Society, a non-profit that helps former inmates find housing, announced Tuesday that it brokered the settlement with the owners of the Sand Castle, a four-building, 917-unit complex in Far Rockaway.

The organization filed a suit in 2014 in Brooklyn federal court accusing the Seagirt Avenue complex of refusing to rent apartments to 20 former inmates based on their criminal histories.

The outfit argued that such a ban was illegal because it disproportionately affected African Americans and Latinos.

The suit attracted the feds’ attention — in 2016, the Obama administration’s Justice Department filed a statement of interest in the case, in which it argued the Fair Housing Act doesn’t allow landlords to make blanket policies that exclude potential tenants based on their criminal histories.

Instead of going to trial, the non-profit says the owners of the building agreed to hand over $1.1875 million — which the Fortune Society says will be compensation for the higher rents it had to pay at other buildings after Sand Castle refused its clients, as well as to cover legal costs.

As a condition of the settlement, Sand Castle’s owners are not admitting any wrongdoing.

“This settlement fires a warning shot across the bow of any landlord in America who blanketly refuses to rent apartments to people with criminal justice involvement,” said Fortune Society president and CEO JoAnne Page in a news release.

Sand Castle’s owners and management company could not immediately be reached for comment Tuesday.