Iran's top leader has warned Saudi Arabia of "divine revenge" over the execution of an opposition Shiite cleric.
Meanwhile while Riyadh accused Tehran of supporting terrorism, escalating a war of words hours after protesters stormed the Saudi embassy in Tehran.
Saudi Arabia announced the execution of Sheikh Nimr al-Nimr on Saturday along with 46 others, including three other Shiite dissidents and a number of al Qaida militants.
It was largest mass execution carried out by the kingdom in three and a half decades.
Sheikh al-Nimr was a central figure in protests by Saudi Arabia's Shiite minority until his arrest in 2012, and his execution drew condemnation from Shiites across the region.
Iran's Supreme Leader Ayatollah Ali Khamenei condemned the execution on Sunday in a statement on his website, saying Sheikh al-Nimr "neither invited people to take up arms nor hatched covert plots. The only thing he did was public criticism".
Iran's powerful Revolutionary Guard said Saudi Arabia's "medieval act of savagery" in executing the cleric would lead to the "downfall" of the country's monarchy.
Saudi Arabia's Foreign Ministry said that by condemning the execution, Iran had "revealed its true face represented in support for terrorism".
The statement accused Tehran of "blind sectarianism" and said that "by its defence of terrorist acts" Iran is a "partner in their crimes in the entire region".
Sheikh al-Nimr was convicted of terrorism charges but denied ever advocating violence.
Sunni Saudi Arabia and Shiite Iran are locked in a bitter rivalry, and support opposite sides in the wars in Syria and Yemen.
Iran accuses Saudi Arabia of supporting "terrorism" in part because it backs Syrian rebel groups, while Riyadh points to Iran's support for the Lebanese Hezbollah and other Shiite militant groups in the region.
The Iranian Foreign Ministry has summoned the Saudi envoy in Tehran to protest, while the Saudi Foreign Ministry later said it had summoned Iran's envoy to the kingdom to protest Iran's criticism of the execution, saying it represented "blatant interference" in its internal affairs.
In Tehran, the crowd gathered outside the Saudi embassy early on Sunday and chanted anti-Saudi slogans.
Some protesters threw stones and Molotov cocktails at the embassy, setting off a fire in part of the building, said the country's top police official, General Hossein Sajedinia, according to the semi-official Tasnim news agency.
He later said police had removed the protesters from the building and arrested some of them, adding that the situation had been "defused".
Hours later, Tehran prosecutor Abbas Jafari Dowlatabadi said 40 people had been arrested on suspicion of taking part in the embassy attack and investigators were pursuing other suspects, according to the semi-official ISNA news agency.
Iranian president Hassan Rouhani, while condemning Saudi Arabia's execution of Sheikh al-Nimr, also branded those who attacked the Saudi embassy as "extremists".
"It is unjustifiable," he said in a statement.
The cleric's execution could also complicate Saudi Arabia's relationship with the Shiite-led government in Iraq.
The Saudi embassy in Baghdad is preparing to formally reopen for the first time in nearly 25 years. Already on Saturday there were public calls for Prime Minister Haider al-Abadi to shut the embassy down again.
Mr al-Abadi tweete on Saturday night that he was "shocked and saddened" by Sheikh al-Nimr's execution, adding that "peaceful opposition is a fundamental right. Repression does not last."
On Sunday, Iraq's top Shiite cleric, Grand Ayatollah Ali al-Sistani, called Sheikh al-Nimr a martyr and said his blood and that of other Shiite protesters "was unjustly and aggressively shed".
Hundreds of Sheikh al-Nimr's supporters also protested in his hometown of al-Qatif in eastern Saudi Arabia, in neighbouring Bahrain where police fired tear gas and bird shot, and as far away as northern India.
The last time Saudi Arabia carried out a mass execution on this scale was in 1980, when the kingdom executed 63 people convicted over the 1979 seizure of the Grand Mosque in Mecca, Islam's holiest city.
Extremists held the mosque, home to the cube-shaped Kaaba toward which Muslims around the world pray, for two weeks as they demanded the royal family abdicate the throne.
Also on Sunday, the BBC reported that one of the 47 executed in Saudi Arabia, Adel al-Dhubaiti, was convicted over a 2004 attack on its journalists in Riyadh.
That attack by a gang outside of the home of a suspected al Qaida militant killed 36-year-old Irish cameraman Simon Cumbers.
British reporter Frank Gardner, now the BBC's security correspondent, was seriously wounded in the attack and paralysed, but survived.