Islamic State claimed responsibility and released a video purporting to show gunmen inside the parliament building and one man, who appeared wounded, on the floor.
The rare attacks were the first claimed by the hardline Sunni Muslim militant group inside the Shia Muslim country. Iran is one of the powers leading the fight against Islamic State militants in neighbouring Iraq and, beyond that, Syria.
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 was shot dead and another one detonated his suicide vest," 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.
"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.
A second attacker was shot dead, he said.
Third attack foiled: Ministry
The Intelligence Ministry said security forces had arrested another "terrorist team" planning a third attack, without giving further details.
"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," said a senior official, who asked not to be named.
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.
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 often urged its fighters to attack Iranian targets and 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. . Do you think we will leave? No! We will remain, God willing."