Conversely, even those among the Iranian leadership who concede that the sanctions have effectively driven a wedge between the state and society see the extensive looting and arson that occurred as the work of agitators trained by the United States and its Middle Eastern allies. The Trump administration’s expressions of support for the protesters and evident satisfaction at the turmoil then gave that accusation some credibility, exacerbating Iran’s paranoia. In the days after the protests broke out, official circles in Tehran began citing a claim by President Recep Tayyip Erdogan of Turkey that Ankara had intercepted intelligence regarding a plot to bring down the Islamic Republic.

Iran’s rulers believe that they crushed an American plot when they crushed the unrest quickly and decisively, and that by doing that, they have rendered President Trump’s “maximum pressure” campaign far less effective. The leadership is also confident that it has demonstrated its determination to defeat any challenge to its hold on power, having killed more than 300 protesters and completely shut down the internet for more than a week. This, coupled with attacks in recent months on oil tankers and energy infrastructure in Saudi Arabia and the United Arab Emirates, which the United States and its allies have attributed to Iran, is treated in Tehran as a demonstration of their power at home and throughout the region.

This implies that, whatever the prisoner swap accomplished, the protests have further diminished opportunities for diplomacy. But if the absence of diplomacy points toward a direct military confrontation, both Washington and Tehran should rethink their positions.

Why negotiate now? On Jan. 6, 2020, Iran is scheduled to take yet another step in rolling back its compliance with the 2015 nuclear accord that the Trump administration has left. This time it might resume enriching uranium to a 20 percent level, which is dangerously close to weapons grade. That could push European signatories to support a snapback of United Nations sanctions. Tehran has already threatened that it will counter such a step by withdrawing from both the nuclear deal and, more important, the Nuclear Nonproliferation Treaty –- steps that North Korea took before developing its nuclear arsenal.

Tehran could also continue to orchestrate attacks in the region that would not give the United States a clear case for war. Mr. Trump’s aversion to responding to such provocations has taught the Iranians that their risks of backlash are limited and manageable. Some in Tehran even argue that Iran could absorb any American military retaliation, and that the closer the United States gets to the threat of all-out war with Iran, the more it will consider returning to negotiations. As the economic situation in Iran worsens, the leadership may feel it has little to lose and little to fear — a dangerous combination.