Last Friday, the U.S. government announced a two-step peace deal with the insurgent Afghan Taliban. In the first step, the United States and the Afghan Taliban will substantially “reduce violence” against each other across Afghanistan for seven days. If satisfied with the reduction, the two sides will sign a broader agreement on withdrawing U.S. troops from Afghanistan; measures for verifying that Afghan territory isn’t being used for international terrorism; and starting intra-Afghan talks for political power-sharing between the Kabul government and the Taliban.

This landmark agreement is intended to end the United States’ longest war. In September, President Trump came close to signing a deal with the Afghan Taliban at Camp David, but the Afghan Taliban killed an American soldier, and Trump called off the summit. This time around, while there are serious risks of failure, the agreed framework provides an important opening to bring U.S. troops home and ease the suffering of Afghan civilians. Here’s what you need to know.

How did we get here?

Reaching this agreement took three years, in part because of formidable hurdles. For good parts of the negotiating period, influential members of the Afghan Taliban felt they had a superior position on the battlefield and could wear out the United States into unilaterally withdrawing.

This was not surprising. Research on civil war suggests that rebels prefer fighting to negotiating when they feel confident about their military prospects because they have battlefield momentum, external state support and illicit economies that fund it. The Afghan Taliban had all of the above, including a resilient insurgency, patrons such as Pakistan and vast income from drug sales.

The Trump White House’s internal politics also caused some difficulties. In 2017, then-Secretary of Defense Jim Mattis and national security adviser H.R. McMaster argued against withdrawal. Trump’s next national security adviser, John Bolton, also opposed a deal.

But top U.S. negotiator Zalmay Khalilzad moved the start-stop peace process relentlessly. Three factors enabled his diplomatic push. First, he decoupled the intra-Afghan power-sharing agreement from a first-order agreement between the United States and the Afghan Taliban. Initially, the United States wanted the Afghan Taliban to negotiate with the Afghan government. By late 2018, however, Khalilzad lost confidence in Afghan President Ashraf Ghani’s ability to forge a united front among his allies and rivals to compel the Afghan Taliban to negotiate, and left him out.

Second, in the words of a Pentagon official, Pakistan played an “indispensable role” in persuading the Afghan Taliban to negotiate — despite Pakistan’s deep support for the Afghan Taliban for most of the war. Pakistan’s calculus appears to have been shaped by a combination of the threat of international sanctions and assurances on some of its concerns, like India’s future role as an influential power in Afghanistan.

Finally, Trump wanted to end the war to fulfill a key campaign promise, providing important political momentum. He leveraged his capital as a hawk to sidestep objections on concessions to the Afghan Taliban. This signaled American seriousness to the Afghan Taliban. It also reduced friction among different U.S. agencies on Afghan policy, which pulled in different directions for much of the war.

The harder part comes next

If both sides do indeed reduce violence and sign the broader agreement, the United States and the Afghan Taliban will have to fulfill some commitments. The United States will need to withdraw a large number of U.S. forces over the next few months, and release Afghan Taliban prisoners. The United States wants the Afghan Taliban to demonstrate their commitment to stop international terrorism and to negotiate a power-sharing agreement with the Afghan political elite.

Both sides will worry about the other side cheating. The United States will closely watch whether the Afghan Taliban fulfills its commitment to break ties with al-Qaeda, and will expect timely implementation of verification mechanisms for monitoring international terrorist activity. The Afghan Taliban will closely watch the U.S. withdrawal, and will synchronize their demobilization with the departure of U.S. soldiers.

Finally, with the intra-Afghan power-sharing discussion, Afghan domestic politics will enter choppy waters. On one hand, Afghan elites are genuinely concerned about whether the Afghan Taliban will engage in good faith discussions toward a power-sharing settlement, and whether the Afghan Taliban will try to reverse human rights gains since 2001, especially on the rights of women.

On the other hand, President Ghani’s domestic standing is in a state of crisis. His recent reelection, announced on Tuesday, was marred by a dispute over the vote count, which his political rivals have rejected. Looking ahead, major centers of Afghan power have vastly varied priorities. Afghan domestic political disputes can derail the peace process at any stage.

How the United States can prevent a civil war and international terrorism

The U.S. government may have to do a lot more to prevent a renewed Afghan civil war, including managing Afghan political elites, shaping the intra-Afghan talks and leaning on Pakistan to keep the Taliban from waging war. It may wish to watch out lest critical parties like Iran and India inflame Afghan groups to oppose a settlement. The United States will need to calibrate economic aid to both Afghan Taliban and Afghan elites to reward good negotiating behavior — and to use the threat of delaying troop withdrawals if the deal begins to collapse.

According to the United Nations, the Afghan Taliban and al-Qaeda continue to collaborate on the battlefield. More recently, al-Qaeda has sought to influence terms of the peace through “shuttle diplomacy” with the Afghan Taliban. This suggests that despite Afghan Taliban’s assurances, al-Qaeda can get a boost in Afghanistan.

To keep al-Qaeda’s threat low, the U.S. government may want to consider maintaining counterterrorism options in Afghanistan that don’t involve troops on the ground. U.S. military and intelligence are experienced — and sometimes effective — in such counterterrorism operations. That may be necessary to prevent al-Qaeda from once again threatening the United States at home.

Asfandyar Mir (@asfandyarmir) is a postdoctoral fellow at the Center for International Security and Cooperation at Stanford University.