Distracted by crises in Iraq, Syria, and Gaza—not to mention Ukraine and the South China Sea—the world forgets the countdown of a time bomb: the interim deal over Iran’s nuclear program expires on July 20. An extension is expected, but that only means rewinding the clock. President Obama has left “all options on the table” to prevent Iran from acquiring nuclear weapons.

A permanent deal can still be reached, war averted, and a rapprochement between Iran and the United States negotiated. That outcome is alas far from assured. Before the warmongering dynamic becomes unstoppable, Americans should ask themselves: Why is Iran our enemy in the first place?

At the heart of the enmity between the United States and Iran is an old-fashioned competition for hegemony in the Middle East. Neither party can claim the moral high ground.

Iran has demonstrated fairly consistent aggressive behavior since the Islamic revolution, from taking diplomats hostage and assassinating dissidents abroad to supporting guerrillas fighting American troops in Afghanistan and Iraq and assisting the Syrian government’s horrific suppression of rebellion.

On the other side, the United States instigated a coup in Iran in 1953 to protect British oil interests and then supported an unpopular despotic regime until it was toppled by revolution in 1979. The United States supported Iraq in its war against Iran even as the former used chemical weapons, mistakenly downed an Iranian civilian aircraft killing 290 civilians, and imposes sanctions against Iran’s nuclear program going far beyond UN requirements.

There’s much more bad blood on both sides, but let’s call it a draw. It’s time to reset relations with Iran. Building on the overtures of a moderate Iranian leader and on the ongoing negotiations over Iran’s nuclear program, a new U.S. policy toward Iran should be based on the principle of punishing bad behavior while not engaging in bad behavior itself.

President Obama should begin by saying that he will not attack Iran without the approval of the UN Security Council. That would render war very unlikely, as Russia and China would be hard to convince. Iran probably believes that President Obama is bluffing anyway. If he weren’t, he would have prepared American public opinion for war as Prime Minister Benjamin Netanyahu has been doing with Israeli public opinion. Obama should then draw a new red line and enforce it: any overt or covert Iranian attack on U.S. soil—or against American personnel or infrastructure anywhere in the world, including cyber warfare—will be met with proportional retaliation.

Once it establishes these first principles, the United States should resume diplomatic relations with Iran and engage Tehran in dialogues about all the conflicts in the region, from Syria to Iraq, Palestine to Lebanon, Afghanistan and more. In the end, Shias and Sunnis, Christians and Jews will stay in the Middle East and must learn to live together. Both the United States and Iran have the power to escalate, but also de-escalate these conflicts. They now both have working relationships with both the Iraqi and Afghan governments, which shows that conflict is not inevitable.

Even as it engages with the Iranian government, however, the United States should not shy away from speaking out in favor of human rights in Iran and indeed in the entire region. Although it is bound to exacerbate tension with Iran and U.S. allies alike, incremental democratization is important to strengthen the stability of the region in the long term. President Obama’s weak support for the Iranian Green Revolution in 2009 was inadequate.

Finally, the United States should ensure that the current negotiations around Iran’s nuclear program succeed. Iran should be allowed to acquire the ability to make nuclear weapons without actually making them, and be subject to a tight inspection regime. The main carrot used to obtain that deal would continue to be the lifting of sanctions, but the prospect of working together to address regional conflicts could be a further inducement. The stick, if Iran refused the deal or broke it in the future, would be to continue and potentially strengthen the UN sanctions. Other UN Security Council members would likely accept tougher sanctions if a unilateral U.S. attack were off the table.

There is a good chance that Iran will accept that deal. Sanctions have hurt the country and brought it to the negotiating table. It is not clear that Iran wants to build a bomb; it might be satisfied with a breakout capability and claim victory by asserting its rights to civilian nuclear energy and diplomatic rehabilitation.

If Iran rejects that deal, so be it. A systematic and balanced analysis by Kenneth Pollack of the pros and cons of air strikes to destroy Iranian nuclear facilities leans against them. In brief, air strikes would only delay, not stop, Iran from acquiring nuclear weapons if it chose to. It is likely that the United States would stumble into a full-scale invasion of Iran, which would be the only way to finish the job. Invasion would be enormously costly financially, politically, and diplomatically.

By contrast, a nuclear Iran can be deterred. Through a package of diplomatic efforts, détente with Iran could also lead to the resolution of other regional problems. If President Obama wants his legacy to be as a peacemaker, Iran must be the place to start.

Didier Jacobs is a contributor to Foreign Policy In Focus.