Saudi Arabia and Iran continue to turn their national struggle into a religious conflict. The first is dangerous. The second could be catastrophic.

Yet Riyadh, America’s nominal ally, just demonstrated that it is the more reckless of the two states.

There is much bad to say about Tehran’s authoritarian and interventionist Islamic regime. But even worse is Saudi Arabia, considered by Washington to be a valued ally and partner.

The Kingdom of Saudi Arabia is essentially a totalitarian state. Riyadh’s execution of noted Shiite cleric Nimr al-Nimr, who had the temerity to advocate democracy, set off riots across the Shiite world.

Freedom House rated the kingdom at the bottom in terms of both civil liberties and political rights. Purported “anti-terrorism” legislation has allowed the “authorities to press terrorism charges against anyone who demands reform, exposes corruption or otherwise engages in dissent.” Last year Human Rights Watch reported that Saudi Arabia continued “to try, convict and imprison political dissidents and human rights activists solely on account of their peaceful activities.”

The U.S. State Department devoted 57 pages to the Saudi monarchy’s human rights (mal)practices. The State Department noted: “The most important human rights problems reported included citizens’ lack of the ability and legal means to change their government; pervasive restrictions on universal rights such as freedom of expression, including on the Internet, and freedom of assembly, association, movement and religion; and a lack of equal rights for women, children and noncitizen workers.”

The Saudi royals are, if anything, even more repressive when it comes to matters of faith. The U.S. Commission on International Religious Freedom reported that the regime “remains unique in the extent to which it restricts the public expression of any religion other than Islam.”

In its latest assessment, the State Department noted that citizens are required to be Muslims and that apostasy may be punished by death. Non-Muslim foreigners and non-Sunni Saudis “must practice their religion in private and are vulnerable to discrimination, harassment, detention and, for noncitizens, deportation.” Obviously, “freedom of religion is not protected under the law.”

Essentially, Saudi Arabia is an early version of the Islamic State that won social acceptance in the West.

Unfortunately, Riyadh doesn’t limit religious repression to home. The licentious royals propagate fundamentalist Wahhabist Islam abroad. The KSA backed the Taliban regime, which shared Riyadh’s enthusiasm for brutal implementation of seventh century Islam. Some wealthy Saudis supported al-Qaida before 9/11.

According to WikiLeaks, U.S. Secretary of State Hillary Clinton confirmed that Saudi money flowed to terrorists. And the monarchy has generously supported extremist Syrian rebels.

Turning the American military into the Saudi royals’ bodyguard also spurred attacks on Americans. The first Gulf War was directed more to safeguard Saudi Arabia than liberate Kuwait; the U.S. garrison left in Saudi Arabia stoked Osama bin-Laden’s anger and was later targeted in the 1996 Khobar Towers bombing. Finally, attacking Iraq created the murderous al-Qaida in Iraq, which became a prolific employer of suicide bombers and morphed into the Islamic State.

Saudi Arabia sells the West oil, but out of necessity, not friendship. Any successor regime would do the same. Anyway, the transformation of the international energy marketplace means Washington need not worry about reduced Saudi oil exports.

On foreign policy Riyadh is as problematic as Iran. Killing a Shiite cleric for standing up to the oppressive Sunni monarchy moved the region closer to multinational sectarian conflict.

Intensifying the Saudi-Iran conflict will undermine Washington’s battle against the Islamic State. The royals have made a political settlement in Syria far harder, if not impossible.

Saudi Arabia also is ruthless in suppressing democracy and human rights in friendly regimes. For instance, Riyadh intervened militarily to back Bahrain’s Sunni monarchy in suppressing the majority Shiite population. The royals lavished money on Egypt’s al-Sisi dictatorship, which has proved to be more brutal than Hosni Mubarak’s rule.

Even worse has been the KSA’s intervention in Yemen’s long-running civil war. The conflict was tribal more than sectarian, but by treating the civil war as yet another proxy fight between Shiite and Sunnis, Saudi Arabia encouraged Tehran to join.

The humanitarian consequences have been horrific. Peter Maurer, head of the International Committee of the Red Cross, said “Yemen after five months looks like Syria after five years.”

Instead of being treated as an ally, Saudi Arabia “should be a pariah,” argued Freedom House President Mark Lagon.

At the very least, U.S. officials should drop the faux intimacy. Riyadh is an important power to be engaged, not supported, endorsed, praised, subsidized and reassured. Regime change is needed more in Riyadh than Tehran.

Doug Bandow is a senior fellow at the Cato Institute and the author of “Foreign Follies: America’s New Global Empire.”