What a difference a year can make. This week, for the first time since Iran’s 1979 revolution, an American President shook hands with an Iranian official. Iran’s foreign ministry quickly dismissed the encounter, between President Obama and Foreign Minister Mohammad Javad Zarif, at a United Nations luncheon in New York, as “completely accidental.” The White House had hoped for more, including a meeting with President Hassan Rouhani. But Iranian officials have been purged from the government for far less. The spokesman for Iran’s judiciary, Gholam-Hossein Mohseni-Ejei, implied that Zarif had engaged in treason. “There is another method of spying that we must be watchful of—an individual who does not appear to be paid by the enemy and does not give classified information, but who has set the scene for the entrance of the enemy,” Ejei, a former prosecutor-general, said. “One who today wants to spy for America, the Great Satan, and coöperates with this country is guilty, a traitor, and is eligible for punishment.”

Yet both the United States and Iran—their current Presidents, anyway—signalled at the United Nations this week that they are prepared to engage further. In the past, Iranian leaders passed up the Secretary-General’s traditional luncheon for leaders at the U.N., to avoid even an accidental brush with Americans. This week, American and Iranian foreign officials instead quietly explored how to convert the historic nuclear agreement into something more.

“We got a deal,” a senior Administration official told me. “Now the question is whether we can have a serious conversation about the region. We’re testing each other to see what is possible.”

Rouhani indicated his interest. “From our point of view, the agreed-upon deal is not the final objective but a development which can and should be the basis of further achievements to come,” he said, at the opening of the U.N. General Assembly, on Monday. “I say to all nations and governments: we will not forget the past, but we do not wish to live in the past. We will not forget war and sanctions, but we look to peace and development.”

I saw Rouhani twice over the weekend. In meetings with journalists, on Friday, and with think-tank scholars, on Sunday, he encouraged more scientific collaboration, academic exchanges, tourism, sports matches, and, eventually, business opportunities with the United States. Now that the nuclear deal is done, however, officials in Washington and Tehran are also thinking strategically. The top priority for both is Syria.

In his U.N. address, Obama chided the theocracy. “Chanting ‘Death to America’ does not create jobs or make Iran more secure,” he said. For the first time, however, the President also held out the prospect of including Iran in a potential solution to Syria’s catastrophic four-year war. “While military power is necessary, it is not sufficient to resolve the situation in Syria,” Obama said. “The United States is prepared to work with any nation, including Russia and Iran, to resolve the conflict.”

America and Iran have backed rival forces in the Syrian conflict. The United States supports the rebels and dissidents who emerged in the original protests against President Bashar al-Assad, in 2011. Iran supports Assad, and is Syria’s closest ally in the Middle East. Its attachment to Syria is partly based on its desire to protect the minority Alawites, but far more important is the protection of brethren Shiites in neighboring Lebanon.

Now leaders in Washington and Tehran have stumbled into an awkward common cause, as the Islamic State (ISIS) has weakened the allies of both countries and consumed half of Syria’s territory. The United States is willing to accept a “managed transition” from Assad’s rule, President Obama said at the U.N. The U.S. appears prepared to allow Assad to be part of the process, apparently allowing him an honorable exit rather than insisting on an immediate forced ouster. In New York, Rouhani repeatedly talked about the need for political reforms in Syria. In private, Iranian officials told me that they are not wedded to Assad over the long term, but they also don’t want to see the collapse of the state, the ruling Baath Party, or the military, which would leave the kind of vacuum that produced chaos in Iraq after Saddam Hussein’s fall. Zarif is now refining a four-point peace plan, which he has outlined to some of his counterparts in New York.

The urgency in both capitals reflects the rapidly changing landscape in Syria and elsewhere in the region. According to U.N. Secretary-General Ban Ki-moon, data shows a seventy-per-cent increase in the number of foreign fighters, from more than a hundred countries, joining the Islamic State this year. The U.S.-led campaign to contain the movement has stalled, despite hundreds of billions of dollars spent on an air campaign that has destroyed more than ten thousand targets and killed thousands of ISIS fighters. The Pentagon admitted this week that it has suspended a five-hundred-million-dollar program to train and equip Syrian rebels.* Russian President Vladimir Putin, in his address to the U.N., castigated the United States for its support of Syrian rebels. “First, they are armed and trained,” Putin said. “And then they defect to the Islamic State.”

The West is also feeling pressure to deal with the fact that the Syrian crisis has produced the greatest humanitarian challenge since the Second World War. Europe is conflicted over absorbing hundreds of thousands of refugees, most of whom are from Syria; the Middle East can no longer cope with four million other Syrian refugees who are rapidly draining resources in Turkey, Lebanon, Jordan, Iraq, and Egypt.

The Syrian crisis “is what keeps everyone up at night, no matter what side of the policy debates you’re on,” the senior Administration official told me. “This is, in many ways, Issue No. 1.” He went on, “The most frenetic and rigorous policy work we are doing is to try to find creative solutions to this problem. We spend hours brainstorming with the Secretary, and he spends hours testing different concepts with his counterparts.”

In an appearance on MSNBC’s “Morning Joe,” on Tuesday, Secretary of State John Kerry said that the international community generally agrees on four principles: ISIS should be destroyed; Syria should remain united within its century-old borders; its government should be secular; and the international community—including rival interests—could oversee a phased transition to replace Assad. The key, he said, is pressuring Assad.

“We are looking for a way to try to get to a point where we can manage a transition and have agreement on the outcome,” Kerry said. “You could end this violence within a very short period of time, have a complete ceasefire, which Iran could control, which Russia could control, which Syria could control, and which we and our coalition could control—if one man would merely make it known to the world that he doesn’t have to be part of the long-term future. He’ll help manage Syria out of this mess and then go off in the sunset—as most people do after a period in public life.”

Iran and Russia are the only countries with influence over Assad and his inner circle. Iran’s allies in Hezbollah have been pivotal in fighting alongside Assad’s forces—with weapons supplied by Iran. The Russian military has now intervened in Syria, deploying more than two dozen war planes and additional troops. It carried out its first air strikes on Wednesday. Yet Iran and Russia are also committed to defeating the Islamic State, which both countries see as a greater threat. ISIS fighters have come within twenty-five miles of Iran’s borders; and Tehran does not want to see a redrawing of the map of the Middle East—for political, economic, military, and sectarian reasons. Russia fears a spillover of Islamic extremism to Muslims at home. Putin acknowledged on “60 Minutes,” on Sunday, that more than two thousand fighters from Russia or former Soviet republics had joined ISIS. “There is a threat of their return to us,” Putin said.