Iranian President Hassan Rouhani on Wednesday urged the country’s courts to prosecute protesters who stormed the Saudi Embassy and consulate over the weekend and said all diplomatic missions deserve protection.

“Diplomatic missions and guests are legally and internationally immune, and attacking these places in the country is against legal and religious laws,” Rouhani said in remarks before his cabinet, even though Iran still celebrates the anniversary of the 1979 seizure of the U.S. Embassy in Tehran.

Rouhani called the attackers criminals whose acts were “erroneous and illegal,” and he said his government would “deal seriously” with those who were in charge of security when a mob angered by Saudi Arabia’s execution of a Shiite cleric climbed the embassy walls unimpeded.

His remarks were the latest attempt to mend a growing rift between Iran and Saudi Arabia that is being felt throughout the region. Djibouti on Wednesday became the latest country to sever diplomatic ties with Iran in solidarity with Saudi Arabia, while Qatar recalled its ambassador in Tehran. The Sunni-ruled country was among a growing list of capitals in the region that have downgraded or cut relations with Iran.

Saudi Arabia and Iran have harbored long-running suspicions and outright hostility toward each other. Here’s why. (The Washington Post)

The diplomatic row comes as Rouhani is on the verge of his long quest to end Iran’s isolation. A landmark nuclear deal it signed with six world powers last year is expected to be implemented within weeks, and the lifting of sanctions will then begin. But that progress appears threatened by the international condemnation being heaped on Iran over the assault on the Saudi Embassy, which has overtaken criticism of the cleric’s execution, one of dozens carried out on the same day in cities across Saudi Arabia.

Despite Rouhani’s interest in having the embassy attackers prosecuted, it is far from certain that they will be punished. About 50 people have been arrested. But Iranian protesters have attacked embassies in the past — including those of Kuwait, Saudi Arabia, Denmark and Britain — and the suspects were released without charges. According to Reuters, some of the embassy attackers took selfies that they posted on social media, in an indication they were not worried about being punished .

Iraq offered to act as mediator between Saudi Arabia and Iran to ease the sharpening of sectarian divisions in the region.

“We cannot stay silent in this crisis,” Iraqi Foreign Minister Ibrahim al-Jafari said during a visit to Tehran on Wednesday.

Rouhani, a relative pragmatist who has taken on hard-liners in the government who oppose any opening with the West, was busy on Twitter laying out his version of the diplomatic meltdown.

He tweeted that Saudi Arabia had beheaded the prominent cleric to “cover up its domestic problems.” That had led to an “unpleasant set of events,” as he described the mob takeover.

Rouhani painted Iran as being at a crossroads, with the nuclear deal’s implementation ushering in economic growth with the end of sanctions.

The tension between the two main sects of Islam, Sunni and Shiite, is one of the factors driving the violence in the Middle East. Here is an overview of the sects’ differences and where adherents live. (The Washington Post)

“We seek good relations with all countries,” he tweeted. “We condemn the attack on #Saudi embassy & consulate. All political missions should be protected.”

He also took several swipes Wednesday at Saudi Arabia for executing the cleric, Nimr Baqr al-Nimr, who was put to death along with 46 other men.

“This great scholar was imprisoned with spurious reasons and executed because of criticizing the Saudi government,” Rouhani told his cabinet. “In legal norms of any country, a person is not executed or beheaded because of criticism.”

According to Human Rights Watch, Iran executed at least 200 prisoners in 2014, the most recent year for which data is available. Opposition sources say an additional 400 executions took place but were not announced.

The group said Iranian law calls for the death penalty for many crimes, including nonviolent offenses that include “insulting the Prophet,” apostasy, same-sex relations, adultery and drug-related crimes.

The furor over the execution and the embassy assault are the latest examples of a years-long buildup of tensions between the two regional rivals, Shiite-ruled Iran and Sunni-ruled Saudi Arabia.

Iran is one of the two major backers of Syrian President Bashar al-Assad, while Saudi Arabia supports anti-Assad rebel factions. U.S. State Department officials have expressed concern that the diplomatic crisis may make it more difficult to hold peace talks on Syria and to fight Islamic State militants.

Read more:

How Saudi Arabia and the Islamic State find common ground in beheadings

The seven most important moments of the Saudi-Iranian rivalry

Who is the Saudi cleric whose death caused the Riyadh-Tehran blowup?

7 remarkable insults in the Iran-Saudi Arabia war of words