Friday’s failure to veto an anti-Israel resolution at the United Nations sets a new low in the annals of American diplomacy.

It was a shocking betrayal of a firm US ally, and of longstanding bipartisan US policy — a sneaky, dishonest move by a lame-duck president to express his pique at the president-elect and land a final vindictive blow on Israeli Prime Minister Benjamin Netanyahu.

In the process, he sought to tie his successor’s hands in a way that no past president — especially his own predecessor, George W. Bush — has ever before done.

President Obama has now empowered the economic war against Israel, just to get even with a leader who dared to defend his own country’s best interests.

A day earlier, Egypt had withdrawn its support for the extremist, one-sided resolution condemning all Israeli activity beyond the 1967 cease-fire lines. That’s when Team Obama spread the word that it would’ve abstained — which prompted Israel’s enemies to revive it for Friday’s vote, where Washington indeed declined to veto.

Never mind that it was virtually identical to a 2011 resolution that Obama’s diplomats did veto, on the ground that the issue of settlements and borders should be decided in direct negotiations, not by a UN-imposed diktat.

Or that successive US presidents — Republican and Democrat alike — have used Washington’s veto power precisely to limit the UN’s involvement in the peace process.

As then-UN Ambassador Susan Rice said in 2011, American’s abstention was not an endorsement of settlement activity but a recognition that such a resolution “could encourage the parties to stay out of negotiations.” On Friday, though, she claimed “the situation has changed.”

Nonsense: The Palestinians still refuse to negotiate without preconditions and unilateral Israeli concessions. Good luck getting them to the table now.

Remember the furor when Trump broke with past practice — not US policy — by taking a call from Taiwan’s democratically elected president? Watch and see who slams Obama’s far greater violation of the bipartisan consensus.

Obama went ahead with this stab in the back of an ally despite the pleading of top Democratic leaders on Capitol Hill. He plainly just had to get even with Netanyahu, and with Trump — whose public intercession Thursday seemed to have indefinitely postponed the vote. Would Obama have abstained if a President-elect Hillary Clinton asked him to veto? Absolutely not.

This measure doesn’t just criticize or condemn Israeli settlements, which Obama (like his predecessors) has done repeatedly. It declares any and all Israeli activity across the Green Line — including in the Old City of Jerusalem and at Jewish holy sites like the West Wall — “illegal” and subject to international action.

In short, it’s a major step in the campaign to delegitimize the state of Israel and subject it to boycott and sanctions.

Which is why the resolution was denounced across the Israeli political spectrum, including by the leader of Netanyahu’s opposition, who called it “dangerous and harmful.”

Again, it also breaks with consensus US policy — which is presumably why the Obama crowd sprang it as a surprise, though it had to have been in the works for months, even as top Obama officials denied rumors of a coming betrayal.

Fortunately, a new president takes over in three weeks — one who doesn’t consider the UN to be a productive body and is in no rush to bend over backward to Palestinian demands.

Trump vowed Friday that “things will be different” once he takes over. We’re counting on it.

As for Barack Obama, it’s a sorry exit. But it’s par for the course for a president who has made everything all about him and his perceived slights. Which is why he’s bungled foreign policy in general — and the Middle East in particular — over the past eight years.

What a profoundly sad — and dangerous — legacy. By every measure, he has taken a giant step away from any chances for peace and betrayed a key ally. Just for some petty personal revenge.