Isis has claimed responsibility for twin attacks at the Iranian parliament and the tomb of Ayatollah Khomeini in Tehran, its first major terror operation on Iranian soil.

State media said that 12 people died in the violence and 42 were injured in what was rare attack on the Iranian capital, lasting five hours. Iran’s Revolutionary Guard has blamed the attack on regional rival Saudi Arabia.

Parliament was in session when four gunmen wielding Kalashnikov rifles stormed the building early on Wednesday, detonating a suicide bomb. Politicians and other staff remained trapped inside, and at least four people were taken hostage, Tasnim news agency said.

A short clip purportedly filmed by the assailants and released by the Isis-linked news agency Amaq shows the injured or dead body of a man in business attire lying on the floor of an office as a man with an assault rifle walks past.

The fighters can be heard shouting in Arabic, rather than Farsi, as gunshots ring out and alarms go off in the background. “Oh God, thank you... Do you think we will leave? No! We will remain, God willing,” one of them says, parroting a slogan popularised by Isis spokesperson Abu Mohammad al-Adnani, who was killed in Syria last year.

Sporadic gunfire could be heard as security services swarmed around parliamentØs entrances before the interior ministry declared that the assailants had been killed on Wednesday afternoon.

Lookout: police officer observes events in a wing of the parliament building in Tehran (REUTERS)

Iran’s deputy interior minister Mohammad Hossein Zolfaghari said security forces had managed to surround the attackers, who originally entered parliament’s main gate dressed as women before they opened fire, shooting them dead in a tense stand off.

At least one security guard died in two suicide bombings at the tomb of Ayatollah Ruhollah Khomeini, the leader of the 1979 Islamic revolution, which was attacked by four more gunmen.

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

The intelligence ministry said security forces had arrested another “terrorist team” planning a third attack, but did not give further details.

Isis is at war with Iran-backed forces in Syria and Iraq, and views Shia Islam as heretical. In recent months there has been a marked step-up in propaganda targeting majority-Shia Iran on the militant Sunni group's news networks, as well as messaging in Persian aimed at recruiting Iranian Sunnis.

Smoke is seen coming from parliament during a terror attack claimed by Is (Reuters)

Analyst Charlie Winter said Isis’s claim, which appeared on the group's official newswire Amaq, had “massive implications” for the region.

“An attack like this could provoke disproportionate counter-terror response in Iran. Iranian officials will be called on to step up intervention in Iraq-Syria big time. If this happens, a more intense ‘Sunni war against Shia Islam’ will pour petrol on [Isis’s] ideological fire,” the research fellow at the International Centre for the Study of Radicalisation at King’s College London added.

“This terrorist attack happened only a week after the meeting between the US president [Donald Trump] and the backward [Saudi] leaders who support terrorists. The fact that [Isis] has claimed responsibility proves that they were involved in the brutal attack,” a statement from Iran's religious Revolutionary Guards said. Saudi Foreign Minister Adel Al-Jubeir, speaking in Berlin, said there is no evidence Saudi extremists were involved.

Tensions are running particularly high in the region following Saudi Arabia and other Sunni powers’ decision to cut ties with Qatar on Monday, accusing it of backing Tehran and militant groups.

The attacks took place less than a month after the re-election of President Hassan Rouhani, a moderate, whose landslide victory defeated candidates supported by the hardline clergy and the Islamic Revolutionary Guard Corps (IRGC), which is responsible for national security.

“The atmosphere is tense. It is a blow to Rouhani. How can four armed men enter the parliament, where a very tight security has always been in place,” a senior official, who asked not to be named, told Reuters.

Dina Esfandiary, a MacArthur fellow at the Centre for Science and Security Studies at King’s College London, said that although Iran has a good track record at foiling previous attacks, the incidents in Tehran would be welcomed by Isis supporters.

Iranian police stand near parliament during a terror attack in central Tehran, Iran, 7 June 2017 (REUTERS) (Reuters)

“It is indeed a boost to Isis morale, especially given that it’s the first successful attack in Iran, and it will help distract operatives from the losing effort in Iraq,” she said.

Isis has called for for increased attacks on unbelievers during Ramadan, during which it says the rewards for jihad in heaven are multiplied.

Wednesday’s events in Tehran mark the fourth major attack worldwide claimed by the group since the holy month began on 27 May.

The car-ramming and stabbings in London Bridge, bombing of an ice cream shop in Baghdad and storming of a casino in Manila have all been claimed by Isis, as well as the attack on an Ariana Grande concert in Manchester on 22 May.

A further suicide truck bombing in Kabul last week killed at least 90 people, although no claim of responsibility has been made. The Afghan intelligence services believe a wing of the Taliban is to blame.

Isis continues to lose control of territory across Syria and Iraq in the face of US-backed operations to destroy its so-called caliphate.

Experts believe it will increasingly turn towards insurgency and terror tactics around the world to prove its enduring legitimacy.