Islamic State claimed responsibility and released a video purporting to show gunmen inside the parliament building.
The attacks took place at a particularly charged time after Saudi Arabia and other Sunni powers cut ties with Qatar on Monday, accusing it of backing Tehran and militant groups.
They were the first claimed by the hardline Sunni Muslim militant group inside in the tightly controlled Shi'ite Muslim country. Islamic State has regularly threatened Iran, one of the powers leading the fight against the militants’ forces in neighboring Iraq and, beyond that, Syria.
The powerful Islamic Revolutionary Guard Corps accused Saudi Arabia of being behind the action, a rare such incident in Iran.
"This terrorist attack happened only a week after the meeting between the U.S. president (Donald Trump) and the (Saudi) backward leaders who support terrorists. The fact that Islamic State has claimed responsibility proves that they were involved in the brutal attack," a Guards statement said.
Saudi Foreign Minister del Al-Jubeir, speaking in Berlin, said he did not know was responsible and there was no evidence Saudi extremists were involved.
The attacks could also exacerbate tensions in Iran between newly re-elected President Hassan Rouhani, a pragmatist, and his rivals among hardline clerics and the Revolutionary Guards.
Attackers dressed as women burst through parliament's main entrance in central Tehran, deputy interior minister Mohammad Hossein Zolfaghari said, according to the Tasnim news agency.
One of them detonated a suicide vest in the parliament, he said. About five hours after the first reports, Iranian media said four people who had attacked parliament were dead and the incident was over.
At least 12 people were killed by the attackers, the head of Iran's emergency department, Pir-Hossein Kolivand, was quoted as saying by state broadcaster IRIB. Some 43 people were wounded.
"I was inside the parliament when shooting happened. Everyone was shocked and scared. I saw two men shooting randomly," said one journalist at the scene.
Soon after the assault on parliament, another bomber detonated a suicide vest near the shrine of the Islamic Republic's revered founder, Ayatollah Khomeini, a few kilometers south of the city, Zolfaghari said.
A second attacker was shot dead, he said. The shrine is a main destination for tourists and religious pilgrims.
"The terrorists had explosives strapped to them and suddenly entered the shrine and started to shoot around," said the shrine's overseeer, Mohammadali Ansari.
The Intelligence Ministry said security forces had arrested another "terrorist team" planning a third attack.
"I was shopping and suddenly heard shooting," said housewife Maryam Saghari, 36, who lives near parliament. "People started to run away from the area. I was very scared. I don't want to live in fear," she told Reuters by telephone.
اولین تصویر از جسد یکی از عاملان تیراندازی در حرم امام خمینی pic.twitter.com/xhfpIeUnVm— روزنامه ایران (@IranNewspaper) June 7, 2017
Television footage showed police helicopters circling over the parliament building, with snipers on its rooftop.
The raids on two of Iran’s most highly-protected sites will jolt Rouhani, who positions himself as a reformer, and his political rivals among the hardline clerics and the Revolutionary Guards, who are responsible for national security.
In an appeal for unity, Rouhani’s chief of staff, Hamid Aboutalebi, took to Twitter to praise the security services.
"If this attacks had happened in any other city in Europe or in the world, it would have left many casualties. Applause to the power and firmness of our revolutionary guards, Basij, police and security forces," he wrote.
Two senior government officials, who asked not to be named, said the blasts might prompt a blame game and exacerbate political in-fighting.
تصاویر جدید از حادثه انفجار مهاجم انتحاری در بیرون حرم مطهر امام خمینی(ره)/ فردی که در حرم امام خمینی خود را منفجر کرده یک زن بوده است pic.twitter.com/Fh0c68rVox— روزنامه ایران (@IranNewspaper) June 7, 2017
"They (hardliners) are very angry and will use every opportunity to grow in strength to isolate Rouhani," said one of the officials.
The other said the attacks, and speculation over who backed them, would push Iran toward "a harsher regional policy".
Iran's tussle with Saudi Arabia for regional influence is being played out in the Yemen war as well as in Syria and Iraq.
The Intelligence Ministry called on people to be vigilant and report any suspicious movement.
Attacks are rare in Tehran and other major cities though two Sunni militant groups, Jaish al-Adl and Jundallah, have been waging a deadly insurgency, mostly in more remote areas, for almost a decade.
Iran's Sistan and Baluchestan province, in the southeast on the borders with Pakistan and Afghanistan, is home to the Balouch minority and has long been a hotbed of Sunni insurgents fighting the Shi'ite-led republic.
Last year Iranian authorities said they had foiled a plot by Sunni militants to bomb targets in Tehran and other cities during the Muslim holy month of Ramadan.
Iranian Foreign Minister Mohammad Javad Zarif, who is
visiting Turkey to discuss the Qatar crisis, told reporters that the attacks will "strengthen the resolve of the Iranian nation against terrorism".
Islamic State has lambasted "heretic" Shi'ite Iran for helping the Syrian and Iraqi governments to fight it.
The video released by Islamic State's news agency Amaq included an audio track of a man saying in Arabic: "Oh God, thank you. [Gunshots]. Do you think we will leave? No! We will remain, God willing."
تصویر محل انفجار انتحاری pic.twitter.com/C95GP8fRfG— روزنامه ایران (@IranNewspaper) June 7, 2017
Banner/thumbnail credit: Reuters