When the last American troops departed Iraq in 2011, after the collapse of a similar security agreement, many Iraqis reveled in a moment of national pride, expressing faith in the government’s ability to maintain security. Since then, the country has fallen back into hellish violence, with thousands killed in sectarian attacks this year.

The Iraqi government cannot even secure Baghdad anymore, despite billions of dollars in oil revenue and well-trained security forces, Mr. Zebari told the Afghan president, according to Iraqi and Afghan officials at the meeting. So how can the Afghan government, which can barely fund 20 percent of what it spends each year, hope to control the country without American help?

The conversation was a resonant moment between two leaders at different points in their respective journeys — one pondering his country’s post-American future, the other contending with it. With the benefit of hindsight, Mr. Zebari reached out to a president he scarcely knew, seizing on their shared experience at the crossroads of American involvement in the Muslim world.

Some of the parallels for Afghanistan are clear. As impasse has deepened into crisis, some of Mr. Karzai’s closest aides have seized on Iraq as proof that the Americans could just walk away, leaving the country’s security forces without military support and training in the middle of a war against the Taliban. Billions in badly needed international aid would also probably dry up, collapsing the economy. Worries about a return to civil war in Afghanistan would leap to center stage.

But Mr. Karzai had heard it all before.

American officials, in fact, have long used the withdrawal from Iraq as a cautionary example when talking with reporters and Afghan officials about the struggle to reach an Afghan security deal. And in the days after Mr. Karzai said he would put off signing the agreement, several senior American officials warned him that they would be forced to begin considering the “zero option” — a total and final troop withdrawal in 2014 — if he did not reverse course.