Gunmen and suicide bombers stormed Iran's parliament and the shrine of its revolutionary leader on Wednesday, killing 12 people in the first attacks in the country claimed by the Islamic State group.
Dozens were injured in the attacks, which targeted two of Iran's most potent symbols: its parliament complex in central Tehran and the mausoleum of Ayatollah Ruhollah Khomeini who led the 1979 Islamic revolution.
The standoff lasted around five hours before all the gunmen holed up in parliamentary office buildings were killed.
IS released a video of the attackers from inside the building via its Amaq propaganda agency -- a rare claim of responsibility while an attack was still going on.
The Sunni jihadists of IS consider Shiite Iran to be apostates, and Tehran is deeply involved in fighting the group in both Syria and Iraq.
The assaults began mid-morning when four gunmen burst into the parliament complex in the centre of Tehran, killing a security guard and one other person, according to the ISNA news agency.
An interior ministry official said they were dressed as women and entered through the visitors' entrance. One eventually exploded a suicide vest while the others were killed by security forces.
At roughly the same time, two assailants entered the grounds of the Khomeini mausoleum, killing a gardener and wounding several other people.
One detonated a suicide vest, while the other was shot dead.
It was not clear whether the shrine attackers were women, as earlier reported, or just wearing female clothing.
Iran's emergency services said a total of 12 people were killed in the two attacks and 43 wounded.
Iran's leaders sought to play down the attacks, with neither President Hassan Rouhani nor supreme leader Ayatollah Ali Khamenei making a statement by early evening.
Parliament was in session as the violence unfolded and members were keen to show they were undeterred, posting selfies showing themselves as calm and continuing with regular business.
Meanwhile, gunshots continued in the neighbouring office buildings, with police helping staff to escape from windows and snipers taking position from rooftops.
Speaker Ali Larijani dismissed the attacks, saying they were a "trivial matter" and that security forces were dealing with them.
The intelligence ministry said there had been a third "terrorist" team that was neutralised before the attacks started.
Tehran was on lockdown, with streets blocked and parts of the metro closed. Journalists and onlookers were kept away from the sites by police.
Interior Minister Abdolrahman Fazli told ISNA he had convened a special meeting of the country's security council.
Messages of support were sent by Russian President Vladimir Putin and from the Syrian foreign ministry.
The three countries are close allies in the fight against rebels and jihadist groups in Syria. Iran has also been helping to battle IS in Iraq, which also sent its condolences.
This has made Iran, the predominant Shiite power, a priority target for IS, which published a rare video in Persian in March warning that it "will conquer Iran and restore it to the Sunni Muslim nation as it was before."
Jihadist groups have clashed frequently with Iranian security forces along the borders with Iraq and Afghanistan, but the country has largely escaped attacks within its urban centres.
The intelligence ministry said in June 2016 that it had foiled an IS plot to carry out multiple bomb attacks in Tehran and around the country.
IS is under increasing pressure, having lost significant territory in the face of offensives now targeting its last two major urban bastions, Raqa in Syria and Mosul in Iraq.
Militant groups are also known to operate in Iran's southeastern Sistan-Baluchistan province, which borders Pakistan and has a large Sunni community.
Jaish-ul Adl (Army of Justice), which Tehran accuses of links with Al-Qaeda, has carried out several armed attacks on Iranian soil in recent years.
Khamenei said on Sunday that attacks by IS in Europe and elsewhere showed that Western policies in the Middle East have backfired.
"This is a fire that (Western powers) themselves ignited and now has backfired on them," he told a gathering of senior officials in Tehran.