Demonstrators protesting against cleric Nimr al-Nimr's execution 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 called for prosecuting "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.
Iranian Supreme Leader Ayatollah Ali Khamenei, criticising Saudi Arabia for the second straight day over Nimr's execution, said politicians in the Sunni kingdom would face divine retribution for his death.
"The unjustly spilled blood of this oppressed martyr will no doubt soon show its effect and divine vengeance will befall Saudi politicians," state TV reported Khamenei as saying.
Iran's Revolutionary Guards had promised "harsh revenge" against the Saudi Sunni royal dynasty for Saturday's execution of Nimr, considered a terrorist by Riyadh but hailed in Iran as a champion of the rights of Saudi Arabia's marginalised Shi'ite minority.
Nimr, the most vocal critic of the dynasty among the Shi'ite 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.
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 Shi'ites, 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 Shi'ite 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".
Iraq Also Furious
In Iraq, whose Shi'ite-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.
"We have received with much sorrow and regret the news of the martyrdom of a number of our brother believers in the region whose pure blood was shed in an unjust aggression," said Iraq's top Shi'ite cleric Grand Ayatollah Ali al-Sistani.
The opinion of Sistani, based in the Shi'ite holy city of Najaf south of Baghdad, carries weight with millions of Shi'ites in Iraq and across the region, including in Saudi Arabia.
Despite the regional 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 ruling Al Saud family has grown increasingly worried as Middle East turmoil, especially in Syria and Iraq, has boosted Sunni jihadists seeking to bring it down and given room to Iran to spread its influence. A nuclear deal with Iran backed by Saudi Arabia's biggest ally and protector, the United States, has done little to calm nerves in Riyadh.
But Saudi Arabia's Western allies, many of whom supply it with arms, are growing concerned about its new assertiveness in the region and at home.
The U.S. State Department said Nimr's execution "risks exacerbating sectarian tensions at a time when they urgently need to be reduced". The sentiment was echoed almost verbatim by EU foreign policy chief Federica Mogherini and an official at the German Foreign Ministry. The State Department also urged the Saudi government to "respect and protect human rights.
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".
The simultaneous execution of 47 people - 45 Saudis, one Egyptian and a man from Chad - was the biggest mass execution for security offences in Saudi Arabia since the 1980 killing of 63 jihadist rebels who seized Mecca's Grand Mosque in 1979.
The four Shi'ites had been convicted of involvement in shootings and petrol bomb attacks that killed several police during anti-government protests from 2011-13. More than 20 Shi'ites were shot dead by the authorities in those protests.
Family members of the executed Shi'ites have vigorously denied they were involved in attacks and said they were only peaceful protesters against sectarian discrimination.
Human rights groups say the kingdom's judicial process is unfair, pointing to accusations that confessions have been secured under torture and that defendants in court have been denied access to lawyers. Riyadh denies torture and says its judiciary is independent.
Analysts have speculated that the execution of the four Shi'ites was partly to demonstrate to Saudi Arabia's majority Sunni Muslims that the government did not differentiate between political violence committed by members of the two sects.
The 43 Sunni jihadists executed on Saturday, including al Qaeda leaders and ideologues, were convicted for attacks that killed hundreds from 2003-06.
"There is huge popular pressure on the government to punish those people," said Mustafa Alani, a security analyst close to the Saudi Interior Ministry. "It included all the leaders of al Qaeda, all the ones responsible for shedding blood. It sends a message."