This column has been updated.

MUNICH — The Afghanistan peace plan floated here this weekend is an election-year gamble: If it works, President Trump can claim credit for ending America’s longest conflict; but if Trump is seen as rushing for the exit, he could trigger a renewed Afghan civil war.

The political dilemma is similar to what presidential candidates have faced with unpopular and inconclusive wars in past decades, in Korea, Vietnam and Iraq. The American public wants out, but adversaries are emboldened by campaign promises to withdraw, and allies are disheartened.

The breakthrough agreement between the United States and the Taliban insurgents, likely to be announced Sunday, will start with a seven-day “reduction in violence.” If this de-escalation holds, it will inaugurate a 135-day drawdown of U.S. troops from the current 13,000 to 8,600.

But what then? Should Trump keep pushing toward zero or opt instead for a long-term residual counterterrorism force of 3,000 to 5,000, as U.S. generals recommend? That decision will test Trump’s political instincts against his responsibilities as commander in chief.

“The president is overly concerned about the problem of still being there in November,” cautions Sen. Lindsey O. Graham, a close Trump ally who has warned frequently of the danger of a too-hasty withdrawal. The South Carolina Republican said in an interview here that he has advised Trump that U.S. troops should leave only if the Taliban meets American demands for a reduction in violence.

“If it’s messaged that we are going to zero without conditions being met, civil war will follow in six months or less,” Graham argued.

A similar cautionary warning came from Sen. Robert Menendez (N.J.), the ranking Democrat on the Senate Foreign Relations Committee. “We have to make very clear that we’re not leaving quickly, because that’s the only way we have a chance of peace.”

Afghan peacemaking has been the major sideshow this weekend at the annual gathering of the Munich Security Conference. Diplomatic discussions have involved Afghan President Ashraf Ghani and Mike Pompeo and Mark T. Esper, the U.S. secretaries of state and defense, respectively. Framing these conversations is Zalmay Khalilzad, Trump’s special representative, who has been negotiating the Afghan pact for the past two years.

Khalilzad has brokered an agreement that, on paper, bolsters a previous effort that crashed last year after the Taliban killed a U.S. soldier and 11 others. The improvements include detailed metrics to verify that violence is declining over the 135-day troop-reduction period, and a Taliban agreement to begin intra-Afghan negotiations within 15 days of signing the agreement with the United States. Khalilzad expects a 70 percent to 80 percent reduction in violence in the 135-day phase of de-escalation, and he has briefed senators that if violence doesn’t abate, the troop withdrawals will stop. This conditionality, if it can be made to work, is the best feature of the deal.

To monitor this de-escalation, U.S. and Taliban representatives will maintain a joint office in Doha, Qatar, to assess data from the war zone and solve problems that arise. Khalilzad assumes that even if targets are met, the Taliban won’t embrace a full cease-fire until the end of the process, in the belief that violence is the insurgents’ only leverage on America and the Kabul government. The United States will assess whether violent incidents are the work of Taliban militants acting as spoilers.

The agreement includes a heavy dose of wishful thinking. Despite a decade of intensive U.S. training, the Afghan army isn’t yet a reliable nationwide peacekeeping force. Unless the Taliban truly buys into cooperating with the Afghan government, the start of U.S. troop withdrawal may bring chaos in Afghanistan — with the army collapsing, the Tajiks and other groups embracing local warlords, and the Taliban declaring a de facto caliphate in areas it controls.

“The odds are that this ends badly,” said Sen. Chris Coons, a Delaware Democrat. “If our objective really is a politically viable withdrawal,” then Trump should recognize that “there’s a strong bipartisan commitment to staying the course and not leaving without a real peace.”

Now, as in 2001, the key to stabilizing Afghanistan may lie next door in Pakistan. To bolster the chances for his peace pact, Trump should give Islamabad a stake in its success — by offering a free-trade deal to Prime Minister Imran Khan in exchange for real, verifiable support in making peace. That’s the best insurance policy he could buy.

Afghanistan teaches the searing lesson that hope for peace and stabilization is not a strategy — and that American presidents regret making promises about Afghan success they can’t deliver.

Read more: