Members of the Iranian Revolutionary Guard secure the area outside parliament during an attack on the complex in Tehran on June 7, 2017 (AFP Photo/Hossein MERSADI)

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 of people were wounded in the attacks, which ended after a standoff lasting several hours as the gunmen holed up in parliamentary office buildings.

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.

Police said all the attackers had been killed by around 3 pm (1030 GMT), some five hours after it started.

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.

At roughly the same time, a team of three or four assailants entered the grounds of the mausoleum of Ayatollah Ruhollah Khomeini, who led the 1979 Islamic revolution, killing a gardener and wounding several other people.

Iran's emergency services said a total of 12 people were killed in the two attacks and 39 wounded.

Two of the attackers at the shrine, one of them a woman, blew themselves up, while another detonated a suicide vest on the fourth floor of the parliamentary office building.

A picture on social media showed police helping staff escape through windows.

Large crowds gathered around cordons to watch as police struggled to disperse the crowds.

Parliament was in session as the attacks unfolded and members were keen to show they were undeterred, continuing with regular business.

Some posted selfies of themselves looking calm, even as gun battles raged in surrounding office buildings and snipers took position on nearby rooftops.

Speaker Ali Larijani dismissed the attacks, saying they were a "trivial matter" and that security forces were dealing with them.

An official at Khomeini's mausoleum in south Tehran said "three or four" people had entered via the western entrance and opened fire, according to the Fars news agency.

It published photos showing the suicide bomber blowing herself up outside.

The intelligence ministry said there had been a third "terrorist" team that was neutralised before the attacks started.

The city was on lockdown, with streets blocked and parts of the metro closed. Journalists were kept away from the shrine by police.

Interior Minister Abdolrahman Fazli told ISNA he had convened a special meeting of the country's security council.

Jihadist groups have clashed frequently with security forces along Iran's 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 a plot to carry out multiple bomb attacks in Tehran and around the country.

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

Iran, the predominant Shiite power, has been helping both Iraq and President Bashar al-Assad's regime in Syria to battle IS.

The jihadist group is under increasing pressure in both countries, 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.

Iran's supreme leader Ayatollah Ali 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.