Iranian protesters stormed the Saudi embassy in Tehran early on Sunday and Shia Muslim Iran's top leader predicted "divine vengeance" for Saudi Arabia's execution of a prominent Shia cleric.
Demonstrators protesting against the execution of Sheikh Nimr al-Nimr broke into the embassy building, smashed furniture and started fires before being ejected by police.
Iran's President Hassan Rouhani condemned the execution as "inhuman", but also urged the prosecution of "extremist individuals" for attacking the embassy and the Saudi consulate in the northeastern city of Mashhad, state media reported.
Tehran's police chief said an unspecified number of "unruly elements" were arrested for attacking the embassy with petrol bombs and rocks. A prosecutor said 40 people were held.
Iran's Supreme Leader Ayatollah Ali Khamenei, criticised Saudi Arabia for the second straight day over Nimr's execution.
"The unjustly spilled blood of this oppressed martyr will no doubt soon show its effect and divine vengeance will befall Saudi politicians," state TV quoted Khamenei as saying.
Iran's Revolutionary Guards had promised "harsh revenge" against the Saudi Sunni royal dynasty for the execution of Nimr, considered a terrorist by Riyadh but hailed in Iran as a hero of the rights of Saudi Arabia's marginalised Shia minority.
Nimr, the most vocal critic of the dynasty among the Shia minority, had come to be seen as a leader of the sect's younger activists, who had tired of the failure of older, more measured leaders to achieve equality with Sunnis.
His execution sparked angry protests in the Qatif region in eastern Saudi Arabia, and in the nearby kingdom of Bahrain.
Relatives of Nimr, reached by telephone, said authorities have informed them that the body had been buried "in a cemetery of Muslims" and would not be handed over to the family.
Although most of the 47 men killed in the kingdom's biggest mass execution for decades were Sunnis convicted of al Qaeda attacks in Saudi Arabia a decade ago, it was Nimr and three other Shias, all accused of involvement in shooting police, who attracted most attention in the region and beyond.
The move appeared to end any hopes that the appearance of a common enemy in the form of the Islamic State militant force would produce some rapprochement between the region's leading Sunni and Shia Muslim powers, allied to opposing sides in wars currently raging in Syria and Yemen.
Khamenei's website carried a picture of a Saudi executioner next to notorious Islamic State executioner 'Jihadi John', with the caption "Any differences?". The Revolutionary Guards said "harsh revenge" would topple "this pro-terrorist, anti-Islamic regime".
Saudi Arabia on Saturday summoned the Iranian ambassador to protest what it described as hostile remarks emerging from Tehran. On Sunday, the United Arab Emirates, a key ally of Saudi Arabia, also summoned the Iranian ambassador and handed him an official letter of protest, state news agency said.
Iraq also furious
In Iraq, whose Shia-led government is close to Iran, religious and political figures demanded that ties with Riyadh be severed, calling into question Saudi attempts to forge a regional alliance against Islamic State, which controls swaths of Iraq and Syria.
Iraq's top Shia cleric Grand Ayatollah Ali al-Sistani described the executions as an "unjust aggression". The opinion of Sistani, based in the Shia holy city of Najaf south of Baghdad, carries weight with millions of Shias in Iraq and across the region, including in Saudi Arabia.
Despite the focus on Nimr, the executions seemed mostly aimed at discouraging jihadism in Saudi Arabia, where dozens have died in the past year in attacks by Sunni militants.
The U.S. State Department said Nimr's execution "risks exacerbating sectarian tensions at a time when they urgently need to be reduced", a sentiment echoed by EU foreign policy chief Federica Mogherini.
UN High Commissioner for Human Rights Zeid Raad al-Hussein said it was not clear those killed were granted effective legal defence, while the scale of the executions was very disturbing "particularly as some of those sentenced to death were accused of non-violent crimes".
Smoke rises from Saudi Arabia's embassy during a demonstration in Tehran January 2, 2016. Iranian protesters stormed the Saudi Embassy in Tehran early on Sunday morning as Iran reacted with fury to Saudi Arabia's execution of a prominent Shia cleric.