How to explain Saudi Arabia's recent actions? Just since the new year, the country has executed 47 people, including the prominent Shia cleric Nimr al-Nimr; ended the ceasefire in Yemen; and broken diplomatic ties with Iran.

These moves might seem bizarre, contradictory, or even self-defeating. But although the regime's reasons for making each of these moves are complex, they all fundamentally spring from the same place: the Saudi regime's profound sense of insecurity.

That insecurity, with respect to its legitimacy at home, its standing in the region, and its fear of losing its grip on power, is behind much of Saudi Arabia's recent behavior. When you understand that, a lot of the things Saudi Arabia does make a lot more sense.

It also helps to explain why Saudi Arabia can sometimes cause so much trouble, whether by the humanitarian crisis it's helping to drive in Yemen, the actions toward Iran that worsen Middle Eastern sectarianism, or the funding of violent Islamist groups in Syria.

Because Saudi Arabia is so intently focused on staving off what it perceives to be numerous and grave risks to its rule, it is more willing to accept or even heighten other forms of risk — including risks that can blow back onto the United States.

Saudi Arabia's core problem: fear

In the eyes of the Saudi leadership, these risks to their regime come partly from external threats and partly from weaknesses and contradictions inherent to the Saudi system itself — which means that a Saudi preoccupation with threats to the regime is, in some ways, baked into the system.

Since the formal creation of the Kingdom of Saudi Arabia in 1932, the Saudi regime has, in its relatively short lifespan, faced a number of serious challenges — both internal and external — to its rule.

The Saudis survived aggression (both direct and indirect) from neighbors, including Iraq and Iran. They survived the damage to their reputation when in 1979 a group of armed Islamic radicals calling for the downfall of the House of Saud seized the Grand Mosque in Mecca. They survived a wave of terrorism led by al-Qaeda in the early to mid-2000s that was explicitly aimed at toppling the regime. And they survived the Arab Spring revolutions and pro-democracy movements.

All this has left the ruling family, while not quite paranoid, certainly feeling insecure. After all, as the saying goes: It's not paranoia if they're really out to get you. That is not to say that the Saudi leaders are mere victims in all this — they are not — nor is it to portray the regime as passive or innocent. It is neither. Rather, it is to articulate how the Saudi leadership came to see itself — rightly or wrongly — as threatened and imperiled.

The roots of the Saudi regime's insecurity

The modern Saudi state is relatively young, as far as countries go. It's only been around since the early 1930s. For most of history, the area we call Saudi Arabia today was not unified. These two facts are important to understanding why the leadership sees itself as insecure.

As historian Alexei Vassiliev explains, from the birth of Islam in the seventh century all the way up to the 18th century, "there was no all-Arabian power, and no peace or stability in the peninsula. For centuries, Arabia had been fragmented, mostly into small or tiny oasis-states or their associations, nomadic tribes or their confederations." In other words, the idea of a single, unitary state composed of all the different tribes of Arabia is sort of a novelty, historically, and the Saudi regime knows this.

So to unite the tribes when the country first formed, and keep them united today, the ruling Saud family uses a powerful mix of religion, money, and force. That's worked so far, but it's not how most countries work — a country like, say, Germany is held together by a common German national identity and by a democratic system with the consent of the governed. The kind of legitimacy the Saudi regime has is much less stable.

When Iran had its Islamic Revolution in 1979, it created another source of insecurity for the Saudi regime. Iran's revolution offered the Muslim world a competing model of Islamic governance — one that was staunchly anti-monarchy. Cameron Glenn of the Woodrow Wilson Center for International Scholars writes that this was a real challenge to the Saudi system:

In Iran, the theocracy strongly rejects monarchies. In 1979, Ayatollah Ruhollah Khomeini called for overthrowing pro-American monarchies in the Gulf, including the Saudi kingdom. Saudi Arabia is home to the two holiest cities in Islam, and the formation of the Islamic Republic – an alternative model of Islamic governance, involving elections – challenged Saudi dominance in the Muslim world.

It wasn't just the existence of the Islamic Republic of Iran that represented a challenge to the Saudi regime; it was also Iran's desire to export its model of Islamic governance around the Muslim world. Despite being a Shia Muslim theocracy in world where the overwhelming majority of Muslims are Sunni, Iran tried to portray itself as the leader and defender of the Muslim world. This presented a direct challenge to the Saudi regime's legitimacy.

The legitimacy of the Saudi royal family rests largely on its religious credentials, which it gets at home from the support of the country's ultra-conservative Wahhabi religious establishment and internationally from being the "custodian" of the two holiest places in Islam, the Prophet Mohammed's mosque in Medina and the Grand Mosque in Mecca.

However, at times these religious credentials haven't been enough to appease everyone. That's where money and force come in. Money to support Islamic causes around the world and build schools that spread the Wahhabi interpretation of Islam to keep the hard-liners at home happy; to build infrastructure and create jobs to keep the citizens happy and complacent; and to send young men who may be susceptible to revolutionary ideas to study in universities abroad, thus getting them out of the country for a few years until they mature into sensible citizens. Money is also useful for building up the state's military and security forces, just in case all the rest of that stuff doesn't quite do the trick and the regime needs to crack down on dissent.

The tools the Saudi royal family used to bring all the tribes together under a single banner when the Saudi state was first founded — religion, money, and force — are the same ones the Saudi royal family uses today to stay in power. But they're still insecure.

The main threats the Saudi regime sees today

Though the Saudi royal family has always been aware of how precarious its grip on power really is, the sheer number of destabilizing forces that threaten the regime today is making them more insecure than ever.

Broadly speaking, the two things the Saudis fear the most are losing power at home and losing their dominant position in the Islamic world to Iran. Nearly every threat the regime sees relates to one (or both) of these. Here's a list of some of the big threats the Saudi regime sees today:

A popular, pro-democracy uprising, like the ones that overthrew the regimes in Egypt and Tunisia

A resurgent Sunni extremist threat, whether from al-Qaeda, ISIS, or an ideologically similar group that sees the Sauds as corrupt and un-Islamic

A Shia uprising in the Eastern Province, where the bulk of Saudi Arabia's oil fields and infrastructure are located and where most of the country's Shia minority also happen to live

Increased Iranian influence on its borders (in Bahrain and Yemen, especially)

Abandonment by the United States in favor of Iran, or even just US disengagement from the region in general, thus depriving Saudi Arabia of its great power protector

The loss of credibility as a responsible custodian of the two Muslim holy places (and perhaps even the loss of custodianship entirely, for example to an international body tasked with administering the areas)

When you look closely at this list, you can see that an awful lot of it, at least in Saudi eyes, might appear either connected or potentially connected to Iran.

Consider, for example, the risk of a Shia uprising in the Eastern Province, which could disrupt Saudi oil production. Phillip Smyth, a researcher at the University of Maryland and adjunct fellow at the Washington Institute for Near East Policy, writes in a recent article in Foreign Policy, "Saudi Arabia’s Eastern Province, which sits on the Persian Gulf and is a vital economic hub for Saudi Arabia, plays a major role in Iran’s sectarian vision."

The idea of the United States becoming friendlier with Iran, particularly in the wake of the Iran nuclear deal, also terrifies the Saudi regime. If the US stops seeing Iran as an enemy to be countered and restrained at all costs, the Saudis believe Iran will become even more powerful and more threatening to Saudi dominance in the region. Similarly, if the US disengages from the region completely, which the Saudis genuinely believe has been happening under the Obama administration, Iran will be left to its own devices and will fill the vacuum left by the withdrawal of the Americans.

Finally, the loss of credibility as a responsible custodian of the two Muslim holy places plays into both the Saudi fear of losing dominance in the region and the fear of losing power at home. Iran has long sought to portray the Saudis as incompetent custodians in an effort to damage their credibility and has even called for an international body to take over administration of these places. For the Saudi royal family, a loss of credibility means a loss of religious legitimacy in the eyes of Muslims, both at home and abroad. It could also mean losing billions of dollars in revenue the Saudi regime takes in from Muslim pilgrims each year.

How these insecurities explain many of Saudi Arabia's recent actions

The Saudi regime knew full well that the decision to execute Nimr, the dissident Shia cleric, would provoke Iran and the various Shia militias it supports in the region, as both Iran and its proxies warned the Saudis of this loudly and clearly and on multiple occasions. But it apparently felt the message the execution would send at home was well worth the risk.

In other words, the decision to execute Nimr was not only — or even primarily — about sectarianism or the power struggle with Iran. It was mainly about sending a message to all its citizens, both Sunni and Shia, about what happens to people who stir up dissent and threaten the stability of the country. And it was about quashing any ideas the Shia in the Eastern Province might be harboring about staging a serious uprising.

The Saudi regime's decision to intervene in the Yemeni civil war can also be understood through the lens of Saudi fear and insecurity. As Sultan Barakat, director of research at the Brookings Doha Center, explains:

Although one can argue over the extent to which the Iranian threat to the Gulf states is real or imagined, the Saudi-led coalition launched Operation Decisive Storm in March to stop Iran from turning Yemen into another Iraq, where it enjoys significant sway over the government and can pressure its Gulf neighbors.

This is why the Saudi regime sees preventing what it believes would be a pro-Iran regime from taking power in Yemen as a top priority.

Saudi fears of an internal uprising and of losing its dominant position in the region also explain why it is spending billions of dollars shoring up the regimes in Egypt, Jordan, Bahrain, Morocco, and elsewhere in an attempt to prevent and in some cases roll back the pro-democracy Arab Spring uprisings that recently swept across the Middle East. Not only does propping up these authoritarian regimes help dampen revolutionary impulses across the region and keep them from spreading to Saudi Arabia, it also ensures Saudi dominance by making the regimes of these countries beholden to the Saudis for financial support.

Another way Saudi Arabia deals with its fears of Iranian influence is by financing Islamist groups that fight the Iranian-backed regime in Syria. Saudi Arabia also fears US disengagement, and responds with the same policy of funding Islamist groups, to fill what it sees as a leadership vacuum — even though doing so is a risk not just to the United States but to itself as well.

It's this sort of calculus that looks irrational to most outsiders and rational to Saudi leaders — not because they're blind to the risks, but rather because they are so intently focused on what they see as the overwhelming and ever-present threats to regime survival that they're willing to take those risks.