In his new book, “Making David Into Goliath: How the World Turned Against Israel” (Encounter Books), Joshua Muravchik, a fellow at Johns Hopkins University’s School of Advanced International Studies, details the historic campaign to demonize the Mideast’s one consistent democracy. Here, he explains how the United Nations went from being an ally to Israel to one of its biggest threats.

The United Nations Human Rights Council has voted to create an “independent international commission of inquiry to investigate all violations of international humanitarian law and international human-rights law” in the current war in Gaza.

Well, actually, not all violations. Only those attributable to Israel — as the resolution makes quite explicit.

And what might those violations be? The very same resolution spells them out, not as allegations but as established findings. “The Council,” it reads, “condemns in the strongest terms the widespread, systematic and gross violations of international human rights and fundamental freedoms arising from the Israeli military operations…since 13 June 2014.”

In other words, Israel’s guilt is already established, and the mandated “investigation” is but a method of punishing Israel by subjecting it to months of verbal laceration and then perhaps sanctions. As the Queen of Hearts said in Wonderland: “Sentence first! Verdict afterwards.”

Hamas is not subject to “investigation.” Its role is to be the star witness for the prosecution. This is not spelled out, but we know the script.

Four years ago, when Israeli forces last entered Gaza, this same council passed a similar resolution, condemning Israel and mandating an “investigation.”

This was the Goldstone Commission, and its principal source of information was testimony at hearings in Gaza arranged by Hamas where witnesses detailed the toll of Israeli strikes while denying the presence of military targets.

Even if not all of them were Hamas members, all knew what Hamas expected them to say — and none would dare defy it.

Richard Goldstone’s report accused Israel of “crimes against humanity,” a special category of crime invented for Nazi war criminals. Two years later, Goldstone renounced his report, saying: “If I had known then what I know now, the Goldstone Report would have been a different document.”

More likely, what changed was not Goldstone’s knowledge but his inability to defend his work to the outside world once he was no longer ensconced in the anti-Israel hothouse that is the United Nations.

This, after all, is the same organization whose General Assembly chastises Israel three times as often as all other countries combined; that has declared Palestinian terrorism to be a “legitimate” means of “fulfilling…one of the goals and purposes of the United Nations”; that once classified Zionism as a form of racism; and that has three special bodies devoted exclusively to agitating against Israel although no other such body exists for any other country.

This astounding bias was not always present. In 1947, the UN voted to partition Palestine, thus legitimating Israel’s birth, and Israel was soon granted admission as a member.

In 1967 and 1973, UN Security Council resolutions 242 and 338 called for “secure and recognized boundaries,” thus implicitly acknowledging that Israel need not relinquish all of the territory captured in the Six Day War.

How did it all turn around so dramatically? During its early decades, in the aftermath of World War II, when American power and prestige was high, the US largely dominated the UN.

Washington pressured its European allies to relinquish their empires, and the UN pushed decolonization.

Thus were scores of new nations born in Africa, Asia, and the Middle East. The UN grew from 51 to 193 members.

Many formed the Non-Aligned Movement. Originally this meant non-aligned in the Cold War, but NAM did not disappear with that conflict.

Today it has 120 members, thus controlling every UN body except the Security Council where the “Permanent Five” hold vetoes.

Fifty-seven of the NAM’s 120 members are members of the Organization of Islamic Cooperation, meaning that the OIC dominates the NAM. And the core of the OIC is the 22-strong Arab League.

Thus, through telescoping leverage have the Arab states turned the UN into a kind of crusade organization against Israel.

The complement to the NAM/OIC/Arab dynamic was also on display in the Human Rights Council’s recent action.

Twenty-nine states voted for this blatantly prejudiced resolution, of which 21 are not free, according to Freedom House, making their presence on the council absurd. The United States alone voted “no.”

England, France, Germany, Italy and other free countries abstained. Beset by guilt over their colonial pasts, Europeans rarely buck the NAM.

This mindset works against Israel in the UN and beyond. In an era of “the rest against the West,” when global cultural elites find virtue only with the “rest,” Israel remains largely “Western.”

For this, it has been sentenced. The predetermined verdict will follow.