Iranian protesters stormed the Saudi embassy in Tehran early on Sunday and Shi'ite Muslim Iran's top leader predicted "divine vengeance" for Saudi Arabia's execution of a prominent Shi'ite 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 Rohani 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.

Open gallery view Iranian protesters set fire to the Saudi Embassy in Tehran during a demonstration against the execution of a prominent Shi'ite cleric, January 2, 2016. Credit: AFP

Iran's Supreme Leader Ayatollah Ali Khamenei, criticized 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 marginalized 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.

His execution sparked angry protests in the Qatif region in eastern Saudi Arabia, where demonstrators denounced the ruling Al Saud dynasty, and in the nearby Gulf 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 Shi'ites, all accused of involvement in shooting police, who attracted most attention in the region and beyond.

Open gallery view Unverified photos appear to show flames rising from Saudi Arabia's embassy during a demonstration in Tehran early on January 3, 2016. Credit: Reuters/TIMA/Mehdi Ghasemi/ISNA

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".

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 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.

Iraq's top Shi'ite cleric Grand Ayatollah Ali al-Sistani described the executions as an "unjust aggression". 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 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.

But Saudi Arabia's Western allies, many of whom supply it with arms, are growing concerned about its new assertiveness.

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. The State Department also urged Saudi Arabia 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 defense, while the scale of the executions was very disturbing "particularly as some of those sentenced to death were accused of non-violent crimes".

The 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 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.