Thirteen people were killed and more than 40 wounded in the attacks on Tehran's parliament complex and the shrine of revolutionary leader Ayatollah Ruhollah Khomeini on Wednesday, the first claimed by the ISIS in Iran.
Trump said the US would "grieve and pray" for the victims, but added: "We underscore that states that sponsor terrorism risk falling victim to the evil they promote."
That was condemned by Iranian Foreign Minister Mohammad Javad Zarif, who tweeted: "Repugnant WH (White House) statement... as Iranians counter terror backed by US clients."
The six attackers were Iranians who had joined the ISIS, the deputy secretary of Iran's Supreme National Security Council, Reza Seifollahi, said on state TV.
They were armed with rifles and pistols and at least two blew themselves up with suicide vests, Iranian media reported.
Police said five people were arrested around Khomeini's shrine on suspicion of involvement, while the intelligence ministry said a third team had been stopped before the attacks started.
ISIS has threatened to step up recruitment within Iran, releasing its first Persian-language video in March in which it threatened to "conquer Iran and restore it to the Sunni Muslim nation as it was before."
The Sunni jihadists of ISIS consider Shiite Iran to be apostates, and Tehran is deeply involved in fighting the group in both Syria and Iraq.
Iran has a sizeable Sunni population along its restive borders with Iraq and Pakistan from which ISIS is hoping to recruit.
"Iranians lit candles for you on 9/11. You kick them while they're down. Classy," tweeted Ali Ghezelbash, an Iranian business analyst.
The US president has long accused Iran of backing terrorism and has threatened to tear up a 2015 nuclear deal between Tehran and major powers.
Even as Washington expressed its condolences on Wednesday, the US Senate advanced legislation that would impose new sanctions on Iran, partly for what the bill described as the Iranian regime's "support for acts of international terrorism".
Iranian security officials counter that it is their regional rival Saudi Arabia -- a close US ally -- that is responsible for funding and spreading the extremism that underpins ISIS.
Iran's Revolutionary Guards accused Riyadh and Washington of being "involved" in Wednesday's attacks, drawing a link to Trump's recent visit to Saudi Arabia.
"For these two actions to happen... after this meeting means that the US and Saudi regimes had ordered their stooges to do this," said Mohammad Hossein Nejat, deputy head of the Revolutionary Guards intelligence branch, according to the Fars news agency.
Other Iranian leaders sought to play down the attacks, with supreme leader Ayatollah Ali Khamenei saying: "These firecrackers that happened today will not have the slightest effect on the will of the people."
Parliament was in session as the violence unfolded and members were keen to show they were undeterred, continuing with regular business.
President Hassan Rouhani said "terrorism is a global problem, and unity to fight extremism, violence and terrorism with regional and international cooperation is the most important need of today's world."
Get Breaking news, live coverage, and Latest News from India and around the world on NDTV.com. Catch all the Live TV action on NDTV 24x7 and NDTV India. Like us on Facebook or follow us on Twitter and Instagram for latest news and live news updates.