Iran’s president urged Thursday for global action against extremism waged in the name of Islam and hinted that a deal over Tehran’s nuclear program could bring greater Iranian cooperation on fighting terrorism.

But Hassan Rouhani also highlighted the deep rifts that stand in the way, blaming U.S. wars and Western-directed policies in the region as creating breeding grounds for militant groups.

“Terror has become globalized,’’ Rouhani said in an address to the United Nations General Assembly. “Extremists of the world have found each other and have put out the call: Extremists of the world unite. But are we united against the extremists?’’

In a wide-ranging speech, Rouhani linked a settlement on negotiations over Iran’s nuclear program with possible increased Iranian assistance on confronting militant factions such as the Islamic State. Rouhani, however, did not bend from Iran’s key demand: retaining the ability enrich uranium.

He further lashed out at U.S. and international sanctions as unjust punishments that remain an obstacle to reaching a nuclear accord after years of talks.

A nuclear agreement would create a chance “for cooperation at regional and international levels, allowing for greater focus on some very important regional issues such as combating violence and extremism in the region,” he said.

Iran is an unwavering opponent of the Islamic State as a threat to its influence in the region. Tehran refuses to take part in an international coalition led by Washington, and Rouhani repeated his call for regional powers to direct the fight against the Islamic State in Iraq and Syria – both key allies of Iran.

Rouhani denounced “errors” by the United States and allies for wars in Iraq and Afghanistan he claimed became training grounds for Islamist militants. He also made indirect – but unmistakable – criticism of regional rivals such as Saudi Arabia for what Rouhani claimed was sponsorship of extremists that fed the ranks of factions such as the Islamic State.

Islamic militants want to create “a fertile ground for further intervention of foreign forces in our region.”

The United States and allies, in turn, has describe Iran as a sponsor of terrorism for its backing for groups such as Lebanon’s Hezbollah and Hamas in Gaza.

``It is astounding that these murderous groups call themselves Islamic,’’ said Rouhani, who cited atrocities such as beheadings.

Last year, Rouhani was in the spotlight at the U.N.’s annual world gathering held shortly after he took office as the successor to the firebrand Mahmoud Ahmadinejad. His landmark phone call with President Barack Obama marked an unprecedented step in attempts to close a more than three-decade diplomatic rift between the nations and make progress on the nuclear talks.

There have been no breakthroughs on either front. But the current U.N. meeting puts the United States and Iran on the same side over their shared alarm over the rise of the Islamic State.

Iran’s Shiite leaders – including the theocracy and powerful Revolutionary Guard – view the Sunni-led Islamic State as a direct challenge to Tehran’s regional reach, which includes close ties to Iraq’s government and Syrian President Bashar al-Assad. Iraqi Shiite militias, backed by Iran, help halt Islamic State advances in northern Iraq, but oppose any military coordination with the United States.

At the U.N. meetings, the Islamic State has overshadowed the ongoing nuclear negotiations. Still, urgency will soon build with the approach of a Nov. 24 deadline to reach an accord.

Iran insists its reactors are only for energy production and medical research. Western nations and others worry that Iran could use its ability to make nuclear fuel to eventual produce warhead-grade material.