Suicide bombers and gunmen attacked Iran's parliament and the Mausoleum of Ayatollah Khomeini in Tehran on Wednesday morning, killing at least 12 people in a twin assault at the heart of the Islamic Republic, Iranian officials and media said.
Islamic State claimed responsibility and released a video purporting to show gunmen inside the parliament building and one body, apparently dead, on the floor.
The rare attacks 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 neighbouring Iraq and, beyond that, Syria.
The raids took place at a particularly charged time, after Iran's main regional rival Saudi Arabia and other Sunni powers cut ties with Qatar on Monday, accusing it of backing Tehran and militant groups.
Attackers dressed as women burst through parliament's main entrance in central Tehran, deputy interior minister Mohammad Hossein Zolfaghari said, according to the semi-official Tasnim news agency.
One of them detonated a suicide vest in the parliament, he said. About five hours after the first reports, Iranian news agencies 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.
"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, who asked not to be named.
Soon after the assault on parliament, another bomber detonated a suicide vest near the shrine of the Republic's revered founder, Ayatollah Khomeini, a few kilometres south of the city, Zolfaghari said, according to Tasnim. A second attacker was shot dead, he said.
The Intelligence Ministry said security forces had arrested another "terrorist team" planning a third attack, without giving further details.
"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.
The raids on two of Iran's most highly-protected sites will jolt both Iran's recently re-elected President Hassan Rouhani, and his political rivals among the hardline clerics as well as the Islamic Revolutionary Guard Corps (IRGC), who are responsible for national security.
Senior government officials have repeatedly described the their country as an "island of stability" in the past.
In an appeal to 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.
"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".
The Intelligence Ministry called on people to be vigilant and report any suspicious movement. Despite unconfirmed reports of a hostage situation, state television said parliament had resumed, and broadcast footage of what it said was the opening session proceeding normally.
"Some coward terrorists infiltrated one of the buildings of parliament. They were confronted. It was not a major issue. Our security forces have taken necessary steps," parliament speaker Ali Larijani said in an open session broadcast live by state TV.
Attacks are highly 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 restive 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 Islamic 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.
Islamic State has lambasted "heretic" Shi'ite Iran for helping the Syrian and Iraqi governments battle Islamic State, which considers Shi'ites to be infidels.
The video released by Islamic State's news agency Amaq included an audio track of a man saying: "Oh God, thank you. [Gunshots]. Do you think we will leave? No! We will remain, God willing."