The agreement last week between the governments of Iraq and Iran to enter a formal relationship to fight the Islamic State group should be deeply troubling to the United States.

The Islamic State, also known as ISIS, is a grave threat to the region and is responsible for the horrifying beheading of American journalists and an aid worker, as well as the brutal slaughter of countless innocent Muslims and Christians in Syria and Iraq.

But as grave a threat as the Islamic State is, Iran is a much greater threat — especially if it acquires nuclear weapons.

In November, Washington decided to extend nuclear talks with the Iranians, despite stalling on the mullahs’ part. The practical effect of the decision is to give the Iranians more time to make a bomb.

Lest anyone believe the Iranians’ assurances that their desire to enrich uranium is purely for peaceful purposes, a September story on the UN Web site raises suspicion.

It says International Atomic Energy Agency Director General Yukiya Amano “noted [that] the agency is not in a position to provide credible assurance about the absence of undeclared nuclear material and activities in Iran, and therefore to conclude that all nuclear material in Iran is in peaceful activities.”

Translation from diplomatic-speak: We’re not buying the Iranians’ story.

A comprehensive study of Iran’s nuclear programs was released in Brussels in November by the nongovernmental organization International Committee In Search of Justice, a group of current and former European parliamentarians and other experts.

The study shows that Iran has a dual nuclear program — a civilian side, which appears to pursue peaceful nuclear energy, and a military program, which skirts sanctions by obtaining dual-use nuclear materials or simply smuggling bomb-making materials into the country. Leadership for the civilian and military programs frequently overlaps, with scientists and others switching places between the two programs as needed.

Meanwhile, the Obama administration largely looks away, instead pursuing negotiations that will never persuade the Iranian regime to give up its nuclear weapons agenda.

The Obama administration largely looks away.

Part of the problem is that the administration doesn’t want to take on the Islamic State directly in Iraq, preferring to provide US military advisers who will play a severely limited role while the Iranian Revolutionary Guard Corps actually provides thousands of troops on the ground.

But expediency in the fight against the Islamic State is a bad strategy for America and for the world. If — more likely, when — Iran develops nuclear weapons, those weapons not only will be used by Iran to intimidate its neighbors but also could well be put into the hands of terrorists whose reach extends far beyond the immediate region.

What should be done? I asked Maryam Rajavi, the leader of the National Council of Resistance of Iran, to give her sense of what might actually persuade the Iranians to give up nuclear weapons. “They will only forgo the bomb if they sense that their survival is in danger and if they feel that the risk of insisting on the nuclear project outweighs the risk of abandoning it,” she told me.

Rajavi talked about the mistakes Washington has made during the negotiations, giving the regime time to improve its ballistic missile programs, as well as enrich uranium. The regime, she said, “will dodge the signing of a comprehensive agreement as long as it possibly can, unless international pressure forces it to retreat.”

Rajavi believes that the movement she leads is a direct threat to the mullahs.

“In their confrontation against a decaying tyranny,” she noted, “the Iranian people have a democratic alternative with a clear platform that seeks a secular and pluralistic republic, gender equality, a society based on respect for human rights and the abolition of the death penalty, abdication of the mullahs’ Shariah laws, providing equal economic opportunities to all, a nonnuclear Iran and peace and coexistence with the rest of the world.”

Too bad the United States has been unwilling to recognize Rajavi’s group, only taking it off the official terrorist list after the group challenged the designation in US courts.

Rajavi is no threat to America, but she may just be the biggest challenge to the real threat we face in Iran.