In a sign that elite security forces had encountered trouble containing the situation, one attacker left the Parliament an hour into the siege, then ran around shooting on Tehran’s streets, only to return to the building, where at least one of the assailants blew himself up on the fourth floor as others continued shooting from the windows.
About the same time, around 10 miles to the south, two attackers entered the west wing of the sprawling Khomeini shrine, a main destination for tourists. According to local news agencies, at least one assailant detonated explosives in the western entrance. Another was reported to have committed suicide by swallowing a cyanide pill.
Iranian state television read out the news of the attack on the Parliament after a regular report on a session in the building, followed by an item on the increasing prices of kindergartens.
The first terrorist attacks in more than a decade in Tehran come just over two weeks after Mr. Trump, with Saudi Arabia and its allies, vowed to isolate Iran. Iran has dismissed those remarks, made at the summit meeting in Riyadh, the Saudi capital, as a scheme by Mr. Trump to sell weapons to Saudi Arabia. The Iranian foreign minister, Mohammad Javad Zarif, has even suggested that Mr. Trump was “milking” Saudi Arabia.
Iran has long accused Saudi Arabia of supporting terrorists in the region, saying the kingdom had facilitated the rise of Sunni extremist groups such as the Islamic State and others in Iraq and Syria.
After Egypt, Saudi Arabia, the United Arab Emirates and other states cut ties with the gas-rich kingdom of Qatar, citing its support for Iran, Tehran has rushed to fill the void, offering to ship food and medicine to Qatar.
“The Saudis feel empowered now,” said Hamidreza Taraghi, a hard-line analyst who is close to Iran’s leaders. “They are now taking revenge in Tehran,’’ he said, adding that Iran’s policy was to drive a wedge between those in the Saudi alliance. “We are now helping Qatar,” he said. “This Saudi alliance means nothing.”
One Iranian security official said the attacks had been a message from Saudi Arabia to Iran. The official said the assaults were meant to teach Iran a lesson. He also said they were intended to test Iran’s reaction.
Others questioned Tehran’s decision to rise to the defense of Qatar. “We are wrong to suddenly seek close ties with Qatar,” said Saeed Laylaz, an economist close to the government. “They have been bankrolling the Sunni terrorist groups, in the same way the Saudis have.”
Iran and Saudi Arabia are the leading nations on the opposing sides of the Middle East split between Shiite and Sunni Islam. Iran has military advisers in Iraq and Syria, and controls and finances militias in those countries and in Lebanon. Tehran also has some influence over the Houthis fighting the government in Yemen, and it often speaks out in support of Shiites in Bahrain, a majority group that Iran says is repressed by the Sunni monarchy.
King Salman of Saudi Arabia accuses Iran of “spearheading global terrorism.” Saudi officials say Iran is plotting to control the region. Saudi Arabia, an autocratic kingdom ruled by a royal family, also opposes Iran’s political ideology, which has a clerical supreme leader but also a president, Parliament and City Councils, chosen in elections where men and women can participate.
While terrorist attacks have become relatively commonplace in Europe and in most of the Middle East, Iran had remained comparatively safe. During May’s election campaign, President Hassan Rouhani often pointed to that fact, lauding the country’s security forces and intelligence agencies for their vigilance.
The coordinated terrorist attacks on Wednesday brought such feelings of security to an end, one analyst said. “Today, it was proved that we are vulnerable too,” the analyst, Nader Karimi Joni, said. “We must anticipate more attacks by the Islamic State, now that we are defeating them in Iraq and Syria,” he added.
While most details of the attacks on Wednesday remained unclear, local news agencies reported that one attacker at the mausoleum was a woman, who blew herself up, while another took cyanide and died.
For many years, Iran suffered from a long and bitter campaign of terrorist attacks by an armed opposition group, Mujahedeen Khalq, a Marxist-Islamic organization that for decades was supported by the former Iraqi dictator, Saddam Hussein. In many of Mujahedeen Khalq’s attacks, when cornered, its members would take cyanide. In 2012, the group was taken off the terrorist list in the United States with the support of conservative Republican politicians.