President Trump gets credit — and takes heat — for many things, but many folks don’t even know about one of his best accomplishments: blocking the federal government’s power grab for control of America’s suburbs.

During the Obama administration, the Department of Housing and Urban Development tried to install Washington bureaucrats as the decision makers for how communities across all 50 states should grow. Using an obscure rule called Affirmatively Furthering Fair Housing, HUD sought to remake America’s cities, towns and villages by forcing any community that was getting federal funds to meet racial quotas.

To do this, HUD applied the notion of “disparate impact,” which unilaterally deems housing patterns to be discriminatory if minority representation is not evenly spread across the jurisdiction. Communities with high concentrations of minorities are automatically labeled segregated.

Westchester served as the petri dish for HUD’s “grand experiment.” On Jan. 1, 2010, the day I was inaugurated as county executive, a federal consent decree signed by my predecessor went into effect requiring Westchester to spend at least $56 million to build 750 units of affordable housing over the next seven years in 31 white communities — or face crippling financial penalties.

Westchester not only met the goal of 750 units on my watch, it exceeded it by 40. A happy ending for everyone . . . except HUD. The administration was intent on taking its AFFH-linked, disparate-impact visions national, and that required villains. The last thing HUD wanted was a suburban community working cooperatively and using its existing zoning framework to build affordable housing without the federal government’s racial micromanagement.

So a year into the settlement, HUD demanded that the county go “beyond the four corners” of the decree and declare its basic zoning rules on things like height, density and safe drinking water as racially “exclusionary.” Single-family homes on quarter-acre lots were deemed potentially “racist” — supposedly because minority members might not be able to afford them.

No one milked this race-baiting angle more than the editorial page of The New York Times, which bizarrely and outrageously accused the county of “defending an ultra-white status quo” (2011); of failing to “remove the barriers . . . that in many villages and towns function as invisible ‘Whites Only’ signs” (2015); and of “keeping Jim Crow’s spirit alive in the New York region” (2016).

Meanwhile, the feds began their campaign to force Westchester’s capitulation by halting millions of dollars in federal funds designated to help the county’s neediest. How’s that for moral high ground?

Missing from the smears were the facts: Westchester is the most diverse county in New York state outside of New York City, and African American and Hispanic populations in the 31 Westchester communities had grown by 56 percent, organically, from 2000 to 2010.

The impasse finally ended with the election of Donald Trump. Elections matter.

But the big win came last month, when — based on Westchester’s experience and expertise from groups like Americans for Limited Government — the Trump administration replaced Team Obama’s AFFH regulation with its own.

Gone is the federal mandate dictating the modeling of communities based on statistical formulas. Restored to local officials is the power that gives them the flexibility to weigh real-world factors in making housing decisions. Restored, too, is the prosecution of bad actors by the courts — not bureaucrats — under the Fair Housing Act.

And builders are now more likely to build affordable housing, since the attached strings have been removed.

The Democratic candidates for president didn’t get the memo. They continue to support radical, divisive and failed housing policies aimed at abolishing single-family residential zoning. And they’d use billions of our tax dollars to local communities — and the threat of lawsuits — to get their way.

The United States needs affordable housing. By replacing social engineering with common sense, guarded by strong nondiscrimination laws, the country is now better positioned to meet that need — and that’s a victory for everyone.

Robert P. Astorino is a former county executive of Westchester