The sudden decision on June 21 by the aging King Salman bin Abdulaziz Al Saud of Saudi Arabia to name his 31-year-old son Mohammed bin Salman as the new crown prince — as well as deputy prime minister — came as a surprise.

Maybe it shouldn’t be.

The newly-minted dauphin replaces 57-year-old Mohammed bin Nayef, the king’s nephew.

The king-in-waiting also continues in his role as defence minister.

This must be seen in the context of the ongoing turmoil in the Middle East, in particular the bitter rivalry between the Saudis and Iran, the two major pillars of Sunni and Shiite Islam, respectively.

The ongoing wars in Syria and Yemen, Hezbollah’s tightening grip on Lebanon and the ostracism of the Gulf state of Qatar all form the backdrop to the move.

The Saudis fear they are losing leverage to their rivals in Tehran.

The Saudis have waged a costly yet inconclusive military campaign against Shiite Houth rebels in Yemen who are allied with Iran — despite bombing campaigns that have led to a huge loss of life and mass starvation and disease.

The new crown prince is one of the key movers behind Qatar’s isolation.

On June 5, Saudi Arabia, Egypt, the United Arab Emirates and Bahrain all severed diplomatic relations with Qatar — accusing it of supporting terrorism.

They cut air, sea and land links with Qatar.

The crown prince maintains that dialog with Iran is “impossible” because Iran’s goal is “to control the Islamic world.”

He has vowed to take the battle to that country.

The Iranians have also escalated the war of words.

The Mehr news agency has contended that Mohammed bin Salman “is an extremist, arrogant, adventurous and hawkish prince who will undoubtedly take a new path to fulfill expansionist goals in the region.”

The Iranians also claim that the recent Islamic State terrorist attack on Iran’s parliament and on the mausoleum of Ayatollah Khomeini, the founder of the Islamic Republic — which left 17 dead — was orchestrated by Riyadh.

On June 13, Iran’s Foreign Minister Mohammad Javad Zarif said that Tehran has “intelligence that Saudi Arabia is actively engaged in promoting terrorist groups” along the country’s eastern and western borders.

Into this complicated mess stepped U.S. President Donald Trump, who is not bothered by Saudi Arabia’s lack of democracy or by its promotion of its austere Wahhabi form of Islam.

Trump has decided that the Saudis need to be supported at all costs against the Iranian threat.

On his recent visit to the kingdom, he backed up the Saudi government by announcing the sale of $110 billion worth of U.S. weaponry to Saudi Arabia’s military.

Saudi Arabia strenuously opposed the nuclear arms deal the U.S. struck with Iran.

Trump is also on record as opposing the nuclear deal, so these developments should confirm the improved working relationship between the Saudis and Washington.

Still, the amount of power the new crown prince has accrued has rankled some older members of the royal family. Some referred to the succession shift as a “soft coup.”

The decision by the 34-member Allegiance Council, which formally approves the choice of crown prince, to confirm the new succession was not unanimous. There were three negative votes. As well, Mohammed bin Nayef has been restricted to his palace and barred from leaving the kingdom.