President Trump is criticizing Federal Reserve Chairman Jerome Powell for getting in the way of our recovery. “Every time we do something great, he raises the interest rates.” On this one, the president is right, and his critics wrong.

Trump isn’t the first president to complain about rising interest rates. Ronald Reagan and George W. Bush did so as well, and somehow the republic survived. But today there’s a special reason why we need to take a second look at the Fed. It’s called moral hazard.

Let me explain. Tightrope artists walk more nimbly when there’s a net under them, and motorcyclists drive faster when they wear a helmet. It’s how we behave when we have a safety net, when we’re insured against risk. When this happens we’re more willing to take greater risks, and that’s a moral hazard.

Here’s the problem: The safety net can encourage people — and governments — to make bad investments, and that’s what happened in the run-up to the financial crisis of 2008-09. The federal government subsidized excessively risky home purchases through Government Sponsored Entities (GSEs) such as Fannie Mae and Freddie Mac, which by 2008 guaranteed three-quarters of US home mortgages.

With the strong backing of liberal politicians, the GSEs’ exposure ballooned from $1.7 trillion in 1994 to nearly $6 trillion by 2007, nearly half of the country’s annual GDP. At no charge from the Treasury, these entities deployed the public credit of the United States to insure subprime housing loans that would not otherwise have passed muster with private lenders. The housing-market crash and the defaults on these bad loans fueled the Great Recession.

Afterward, you might have expected that banks would be disciplined for their risky lending; instead, they were bailed out. The smartest of Keynesian macroeconomists, led by Federal Reserve Chairman Ben Bernanke, argued that printing more money was the best way back to prosperity. The money would end up in the hands of consumers who would use it to make purchases. This, in turn, would increase the demand for goods and services and lead firms to hire more workers to meet the demand.

The Fed lowered short-term interest rates, first to 0.5 percent and thereafter to a range from 0 percent to 0.25 percent. It then embarked on a quantitative-easing program, buying long-term government bonds — an even more obvious way of priming the monetary pump and stimulating the economy.

And it purchased Fannie Mae and Freddie Mac’s toxic mortgage-backed real-estate securities. Meanwhile, the US government pumped nearly $1 trillion into the economy through President Barack Obama’s stimulus package.

All this followed a Keynesian playbook that prescribed demand-side responses to recessions, flooding the market with money to get people buying and restart the economy. Indeed, it was Keynesianism on steroids: Washington experimented with every demand-side mechanism it could think of, including cash for clunkers, home-buyer tax credits and mortgage-relief plans.

What this reaped was a stalled economy, not the recovery that followed past downturns. Annual growth rates of 1 to 2 percent were a “new mediocre,” International Monetary Fund managing director Christine Lagarde told us. Get used to it.

Except that’s not what’s happened. Thanks to the policies of the Trump administration, the US economy has come roaring back, and that has encouraged the Fed to raise interest rates, triggering Trump’s ire.

Trump has a point. The Fed’s mandate includes a directive to promote maximum employment, which means when a president gives us a jobless recovery through wasteful laws and regulations, he’ll be rewarded with low interest rates and all the means by which Bernanke’s Fed tried to prop up the economy. But when a president reverses this through sensible tax and regulatory policies that return the country to full employment, he’ll be punished with higher interest rates.

That doesn’t sound fair, and, worse, it creates a moral-hazard problem: The prospect of the Fed’s safety net will encourage a future president to adopt Obama’s wasteful policies.

This suggests the need to rethink Fed policies. Right now, the Fed sets interest rates as though boom and bust cycles were natural occurrences, and not the result of government policies. What it’s really doing is propping up wasteful government programs while passing the cost to taxpayers and the pain to more efficient administrations that foster job growth.

It stinks, and Trump has every reason to be upset.

F.H. Buckley’s new book is “The Republican Workers Party: How the Trump Victory Drove Everyone Crazy, and Why It Was Just What We Needed.”