If it is true that the best defense is a good offense, President Obama should be celebrating in the end zone now. Obviously furious over criticism that his anti-terror policies are weak and that the Orlando slaughter proves it, he went on a televised tirade to let America know he’s mad as hell and not going to take it anymore.

He laid waste to a field of straw men, cable-TV pundits and the always-evil “partisan rhetoric,” by which he means anyone who disagrees with him. It was a striking display of personal anger and pent-up grievances — and a total failure of leadership during a national crisis.

It also, inadvertently, captured why Donald Trump was able to brawl his way to the GOP nomination. All his nice Republican rivals couldn’t stir voters because they never knew how to rattle Obama the way Trump is doing. The president didn’t mention Trump yesterday, but the whole speech was nothing but a desperate and incoherent reaction to Trumpism.

As such, it was a huge moment in the general-election campaign, even though it comes before the nominees are formally crowned. For one thing, it showed that Obama’s plan to campaign against Trump as if he is running for his own third term won’t be a cakewalk for the president or his legacy.

For another, the Obama-Trump war means Hillary Clinton could be overshadowed in what was supposed to be her campaign for vindication. Throw in her husband and the stage is going to get crowded with alpha males competing for attention.

Obama’s demeanor and tone were far from presidential — tantrums rarely are. Nor was he effective in rallying the nation to his cause. No surprise there. His cause is himself, always and only, and his greatly diminished historic presidency looks especially insignificant next to the bloodshed in Orlando. The iconic redeemer who promised hope and change never seemed so small and hopeless.

America saw Barack Obama at low tide yesterday, revealed as brimming with fury and bankrupt of ideas and even sympathy for the dead. The man who had an answer for everything and a solution to nothing is now also out of excuses.

Jimmy Carter’s infamous “malaise” speech in 1979 was inspirational by comparison. Carter focused on a “crisis of confidence in the future” while Obama scolded the country for losing confidence in him. Carter tried to lift up America, Obama came to put it down.

He meant his attacks to be especially vicious, but the spectacle was more sad than provocative. The president needs a rest from the job as much as we need a new president.

Forty-nine innocent people were gunned down in a gay nightclub by an Islamic terrorist, another 53 lie wounded, yet Obama feels only his own pain. Public confidence in his effort to combat terrorism on his own peculiar terms while soft-pedaling the links to Islam were among the casualties in the Pulse nightclub. The world knows he’s a failure and he can’t stand the embarrassment.

So he lashed out at Trump, who dares not only to point out the obvious, but to rip away the veil of euphemism as he lunges for the jugular. Think Low Energy Jeb, Lyin’ Ted, Little Marco and Crooked Hillary. They’re all nasty and personal, yet ruthlessly accurate.

Now it’s Obama’s turn in the crucible. Cosseted by his media water carriers and surrounded by sycophants, he isn’t accustomed to dealing with a heavyweight street fighter.

Oh, would he love to run against Mitt Romney again. That way, he would never have to take a real punch.

The ostensible reason for Obama’s speech was an update on Orlando and to assert success against the Islamic State. The real reason was to lecture America about how right he is about everything on terrorism, from how to fight it to how to talk about it, and how Trump is worse than wrong.

At one point, Obama denounced politicians who tweet and go on cable TV. My first reaction was to wonder whether he meant Trump or Clinton, or both. Of course, when Obama does those things, it’s cool.

Most telling, and least surprising, was that his defense of why he doesn’t say “radical Islam” revealed there’s no there there. The idea that linking terrorism to Islam smears the entire religion is preposterous, as is his claim that it “does the terrorists’ work for them.”

We are long past the point where Obama’s saying so makes it so, or even worth discussing. His fundamental problem is that he has nothing to show for his approach. If he had been right over the last eight years, we should be seeing big-time gains by now.

Instead, Islamic terrorism is growing around the world and the body count is mounting at home. More and more police officers are being pushed into counterterrorism duties as the nation’s fear meter surges. It is noteworthy, too, that the most successful attacks since 9/11, in San Bernardino and now in Orlando, happened in cities that were not viewed as prime targets. That means no place is safe.

Meanwhile, the moderate American Muslims Obama is always defending are almost all silent in the face of unspeakable horrors committed in the name of their religion.

The president has no substantive response to any of that, and not much desire to find one. His passion is reserved for criticism of Americans who don’t see things his way, as though he can fool them one more time.

At the height of his anger, he warned that even talking about terrorism with a focus on Islam “makes Muslim Americans feel their government is betraying them.”

In that case, they are joining a very large club, with two out of three Americans saying the country is on the wrong track. Millions of the disenchanted are turning to Trump because they concluded that not only had their government betrayed them, but that both political parties were in cahoots to keep them down.

Of course, because most of them are working-class people who play by the rules and don’t demand special favors or government handouts, they’re not important in Washington.

So they found an outsider they believe will speak for them and fight for them. That’s why every punch Trump threw at the GOP establishment during the primaries, and every punch he throws at Clinton and Obama now, brings him more support and more loyalty.

It’s also why Trump is going to keep swinging all the way to November. It’s not elegant or pretty — in fact, it’s often coarse and vulgar. But it’s clearly getting under the president’s very thin skin, and that’s why it won’t stop.

Obama had better get used to it. Finally, he may have met his match.