Iran hit out at the United States and Saudi Arabia as tens of thousands attended the funeral on Friday for those slain in the first attacks in Iran claimed by the militant Islamic State (IS) group.

The intelligence ministry, meanwhile, said on Friday that 41 people suspected of being “agents of Daesh (IS)” had been arrested in the aftermath of Wednesday’s attacks.

“Death to America”, “Death to the Saud” ruling family, and “We are not afraid”, shouted the crowd behind a lorry bearing the coffins of 15 of the 17 people killed.

Burials were held in the provinces for the two others killed when gunmen and suicide bombers stormed Tehran’s parliament complex and the shrine of revolutionary leader Ayatollah Ruhollah Khomeini. Fifty people were wounded in the attacks.

Supreme leader Ayatollah Ali Khamenei had initially called the attacks “firecrackers” that “will not have the slightest effect on the will of the people”. But on Friday he turned his wrath over the attacks on the United States and Saudi Arabia.

“Such acts will have no other result than to reinforce hatred for the US government and its agents in the region, like the Saudi (government),” Khamenei wrote in a message of condolence.

At a ceremony held in parliament, attended by newly re-elected moderate President Hassan Rouhani, speaker Ali Larijani also attacked the United States and Saudi Arabia.

He called regional rival Saudi Arabia “a tribal state very far from anything like a democracy”, and denounced US sanctions against Iran over its ballistic missile programme.

The US “knows that the Revolutionary Guard and its Quds force are the most important regional forces fighting terrorists”, Larijani said. The imposition of the sanctions “demonstrates their alignment with terrorists in the region”, he added.

After prayers at Tehran University, a long procession left central Tehran for Behesht-i-Zahra cemetery near the Khomeini mausoleum, 20 kilometres away.

The attacks on two of Iran’s most symbolic landmarks were carried out by five armed men, including suicide bombers who blew themselves up.

The intelligence ministry said they were Iranians who had joined IS and travelled to its strongholds in Iraq and Syria before returning home.

Iran is a key fighting force against IS and other groups in Iraq and Syria.

IS released a video overnight of the five attackers before the assault, via its Amaq propaganda agency.

“Allah permitting, this is the first brigade that was established (in Iran) but it will not be the last,” one said, as the group sat masked in a circle with their weapons. The group had earlier released footage of the attackers from inside the building, also via Amaq — a rare claim of responsibility while an assault was still going on.