Several demonstrators stormed the Saudi embassy in Tehran and torched parts of the building, in reaction to the execution of a top Shiite cleric known for his activism against the Sunni government in Saudi Arabia.
"A group of angry Iranians" attacked the premises after the Saudi regime carried out a death sentence against Shiite cleric Nimr al Nimr, news agency Tasnim said.
Police clashed with demonstrators and several rioters were arrested before security forces brought the situation under control. Some reporters and photographers were arrested briefly in the chaos.
The Iranian Foreign Ministry temporarily banned all gatherings in front of the Saudi embassy in Tehran and the Saudi consulate in Mashhad.
"We understand the anger of citizens, but nevertheless they are not to assemble in front of any of the diplomatic missions of Saudi Arabia," Foreign Ministry spokesman Jaber Ansari said.
Saudi Arabia angered the region's Shiites after al-Nimr was executed along with 46 other people. An Interior Ministry spokesman said they had been found guilty of adopting extremist ideologies, causing explosions and killing civilians and security officers.
Saudi sources said four of those executed were Shiite. The charges suggested the remainder were probably linked to the Sunni extremist group al-Qaeda.
Al-Nimr, 55, had been condemned to death in 2014 on charges of causing sectarian strife and disobeying the country's ruler.
Iran, Saudi Arabia's regional Shiite rival, called the execution politically and religiously motivated.
"Instead of focusing on [Islamic State] terrorists threatening the region and the whole world, the Saudis execute a prominent figure like al-Nimr," Ansari said, referring to the radical Sunni militia mainly active in Syria and Iraq.
The US government expressed concern that the execution could exacerbate sectarian tensions "at a time when they urgently need to be reduced."
In Iraq, religious authorities from the Sunni minority were among those condemning the execution.
Iraq's Dar al-Ifta, a key Sunni religious body, said it feared the execution "could cast the sons of the Islamic community into new internal conflict."
Iraq's Shiite Prime Minister Haider al-Abadi said opinions and peaceful opposition "are rights protected by divine and international law.
"Their violation will have repercussions for the security and stability of the region's peoples and their social fabric," he warned on Facebook.
Saudi Arabia defended the executions, saying the Iranian comments were "irresponsible."
"When implementing court rulings, the kingdom does not pay attention to any threats or comments," Interior Ministry spokesman Mansour al-Turki said.
Saudi Arabia's top state-appointed cleric, Abdel-Aziz al-Sheikh, also advocated the executions, saying they were "fair and aimed to boost security."
Al-Nimr, a Saudi national, repeatedly demanded increased rights for the Shiite minority, who make up some 15 per cent of the Saudi population.
Toby Matthiesen, author of a recent book about Shiite dissent in the kingdom, wrote on Twitter that the execution of al-Nimr was "the first execution of a political (as opposed to a militant) dissident in decades in Saudi Arabia."
Chris Doyle, a commentator on Middle East affairs and director of the Council for Arab-British Understanding, said the execution was likely to exacerbate sectarian tensions in the region.
The execution of al-Nimr "won't help Saudi Arabia's image as an anti-Shia state, in the way that it treats the Shia, in the way that it has stoked up sectarian rhetoric," Doyle told dpa.
"Iran also stokes up sectarianism," he said, "the other way round."
Saudi Arabia's Shiites complain of discrimination, saying they often struggle to get senior government jobs and benefits available to other citizens.
The government denied the claims and said al-Nimr had followed "in the footsteps of the devil," the official Saudi Press Agency quoted an Interior Ministry statement.
"Through his terrorist acts, innocent blood was shed with the goal to shake stability in this country."
Federica Mogherini, the European Union's foreign policy chief, said al-Nimr's death had "the potential of inflaming further the sectarian tensions that already bring so much damage to the entire region, with dangerous consequences."
Al-Nimr's backers protested in Sunni-ruled Bahrain, which has a Shiite majority, with people chanting slogans against the Saudi and Bahraini governments and clashing with police, witnesses said.
Saudi Arabia is believed to have executed 137 people on various offences last year.
Beheading is a common method of execution in Saudi Arabia, which applies a strict interpretation of Islamic law. The country ranks among the top nations for carrying out the death penalty.