DOHA, Qatar — The United States and the Taliban signed a peace deal Saturday that calls for the full withdrawal of American troops from Afghanistan within 14 months — a turning point in an 18-year war that has cost tens of thousands of lives.

The complete withdrawal of U.S. and coalition troops is contingent on a guarantee from the Taliban that Afghan soil will not be used by terrorists with aims to attack the United States or its allies, according to a copy of the agreement released by the State Department as the signing was underway.

But the Taliban does not have full control over all areas outside government hands. Other factions, including breakaway Taliban groups and others claiming allegiance to the Islamic State, have footholds around the country and potentially could grow stronger without U.S.-led forces to keep them in check.

Other major challenges lie ahead: Afghanistan's deepening political crisis, a controversial prisoner swap and complex intra-Afghan talks that could drag on for months or longer.

Even the relative calm in Afghanistan over the past week — a precondition for the peace deal signing — was thrown into question.

The spokesman for the Taliban's Qatar office, Suhail Shaheen, told The Washington Post that the Taliban hoped for a "permanent solution" to violence levels. But the pledge for a week-long period of reduced violence has "ended," he said.

U.S. envoy Zalmay Khalilzad and Taliban deputy leader Mullah Abdul Ghani Baradar inked the deal on an ornate desk in an opulent hall at a hotel in Doha, Qatar, on Saturday. Secretary of State Mike Pompeo attended the ceremony and witnessed the signing while seated across from the two men.

Pompeo called the moment "historic" and said the Taliban needed to live up to commitments to break with al-Qaeda and reduce violence.

The deal signing came after a seven-day "reduction in violence" in which U.S., Afghan and Taliban forces pledged not to carry out offensive operations. The agreement does not specify whether that commitment would continue. Instead, it notes that a cease-fire would need to be agreed upon in intra-Afghan talks that are expected to start in 10 days.

The withdrawal will begin with a drawdown to 8,600 troops within 135 days, according to the document. During that time, U.S. allies and coalition members will also proportionally draw down their forces.

Trump called the deal “a powerful path forward to end the war in Afghanistan and bring our troops home” in a statement released Friday.

In Kabul, U.S. Defense Secretary Mark T. Esper said there is real hope for peace in Afghanistan, but he warned the Taliban to meet its obligations under the deal.

“The United States will not hesitate to nullify the agreement,” Esper said at a ceremony with NATO Secretary General Jens Stoltenberg and Afghan President Ashraf Ghani that was held at the same time as the signing in Doha.

Stoltenberg called Saturday a “victory for peace” and noted increases in women’s rights, life expectancy and respect for human rights.

“The challenge now is to secure these gains,” he said.

Ghani also pointed to advances made in Afghan society, including freedom of speech and the advancement of women’s rights.

“Today can be the moment of overcoming the past,” he said.

But criticism of the pact came from Trump’s former White House team.

Former national security adviser John Bolton said the deal brings an “unacceptable risk to America’s civilian population.”

“Legitimizing Taliban sends the wrong signal to ISIS and al-Qaeda terrorists, and to America’s enemies generally,” Bolton wrote in a tweet.

Under the deal, the Afghan government must assemble a negotiating team that will work with the Taliban to agree on the makeup of the country’s new government. The peace deal stipulates that those talks must begin by March 10.

Ghani faces the challenge of building an inclusive negotiating team to represent the Afghans who are not aligned with the Taliban. The announcement of disputed election results earlier this month has left the government in Kabul deeply divided and has the potential to undermine Ghani’s mandate to form that team.

Another potential obstacle is a planned prisoner exchange. The text of the peace deal released by the State Department said the prisoner swap — the release of thousands of Taliban prisoners in Afghan custody for about 1,000 members of the Afghan security forces in Taliban captivity — must occur by March 10 when inter-Afghan talks are set to start.

The peace deal also stated that the United States will work to remove members of the Taliban from sanctions lists and “seek economic cooperation and reconstruction with the new post settlement Afghan Islamic government.”

Following the signing ceremony in Doha, Shaheen, the Taliban spokesman, told The Post that the Taliban is committed to the deal, but that doesn’t mean violence levels will remain low in Afghanistan.

“That was for making the environment conducive to sign the deal,” Shaheen said. The Taliban hopes to achieve a “permanent solution” to violence levels in Afghanistan, “but right now [there is] no such understanding of a cease-fire or reduction in violence.

Shaheen also suggested there may be some gray area in the Taliban’s commitment not to allow terrorist groups to use Afghan soil to plan and launch attacks against the United States and its allies.

A peace deal with the Taliban has been a critical foreign policy goal for Trump, who campaigned on ending the war. But he has faced fierce criticism from the Afghan government as well as from fellow Republicans at home.

Afghan officials have repeatedly criticized the United States for excluding them from talks with the Taliban. Any significant withdrawal of U.S. forces from the country is expected to place increased pressure on Afghan government forces, whose casualty rates continue to rise.

On Thursday, a group of Republican lawmakers released a letter warning that the Taliban has “a history of extracting concessions in exchange for false assurances.”

“A full-scale U.S. withdrawal” would “allow terrorist groups in Afghanistan to grow stronger and establish safe havens from which to plot attacks against us,” the letter continued.

Trump’s Friday statement said “ultimately it will be up to the people of Afghanistan to work out their future. We, therefore, urge the Afghan people to seize this opportunity for peace and a new future for their country.”

U.S. and Taliban negotiators were close to signing a peace deal in September, but the effort was scuttled by Trump after an attack by the Taliban killed a U.S. soldier.

Since then, Khalilzad has sought confidence-building measures to bring both sides back to the table. In November, the Taliban released two Western hostages in exchange for the release of senior militants linked to the Taliban by the Afghan government. And over the last week, both sides reduced violence nationwide.

It is unclear if the reduction in violence will hold in the coming weeks as Afghan government officials and the Taliban begin talks. The Afghan government initially demanded a cease-fire before agreeing to talks with the Taliban.

As peace talks between the U.S. and the Taliban gained momentum last year, violence in Afghanistan intensified. The United Nations’ annual report on civilian casualties released this month said 3,403 civilians were killed and 6,989 were injured in 2019.

The United Nations Assistance Mission in Afghanistan has documented more than 100,000 civilian casualties since the organization began its tally in 2009.

George and Lamothe reported from Kabul. Sharif Hassan in Kabul and Haq Nawaz Khan in Doha, Qatar, contributed to this report.