The United States signed a peace agreement with Taliban militants on Saturday aimed at bringing an end to 18 years of bloodshed in Afghanistan and allowing U.S. troops to return home from America's longest war. Under the agreement, the U.S. would draw its forces down to 8,600 from 13,000 in the next 3-4 months, with the remaining U.S. forces withdrawing in 14 months.

The complete pullout, however, would depend on the Taliban meeting their commitments to prevent terrorism.

President George W. Bush ordered the U.S.-led invasion of Afghanistan in response to the Sept. 11, 2001 attacks. Some U.S. troops currently serving there had not yet been born when the World Trade Center collapsed on that crisp, sunny morning that changed how Americans see the world.

Get Breaking News Delivered to Your Inbox

It only took a few months to topple the Taliban and send Osama bin Laden and top al-Qaida militants scrambling across the border into Pakistan, but the war dragged on for years as the United States tried establish a stable, functioning state in one of the least developed countries in the world. The Taliban regrouped, and currently hold sway over half the country.

The U.S. spent more than $750 billion, and on all sides the war cost tens of thousands of lives lost, permanently scarred and indelibly interrupted. But the conflict was also frequently ignored by U.S. politicians and the American public.

U.S. Secretary of State Mike Pompeo attended the ceremony in Qatar, where the Taliban have a political office, but did not sign the agreement. Instead, it was signed by U.S. peace envoy Zalmay Khalilzad and Taliban leader Mullah Abdul Ghani Baradar.

U.S. peace envoy Zalmay Khalilzad, left, and Mullah Abdul Ghani Baradar, the Taliban group's top political leader, shake hands after signing a peace agreement between Taliban and U.S. officials in Doha, Qatar, Saturday, Feb. 29, 2020. Hussein Sayed/AP

The Taliban harbored bin Laden and his al-Qaida network as they plotted, and then celebrated, the hijackings of four airliners that were crashed into lower Manhattan, the Pentagon and a field in western Pennsylvania, killing almost 3,000 people.

President Trump has repeatedly promised to get the U.S. out of its "endless wars" in the Middle East, and the withdrawal of troops could provide a boost as he seeks re-election in a nation weary of involvement in distant conflicts.

Mr. Trump has approached the Taliban agreement cautiously, steering clear of the crowing surrounding other major foreign policy actions, such as his talks with North Korea.

Last September, on short notice, he called off what was to be a signing ceremony with the Taliban at Camp David after a series of new Taliban attacks. But he has since been supportive of the talks led by his special envoy, Zalmay Khalilzad.

Under the agreement, the Taliban promise not to let extremists use the country as a staging ground for attacking the U.S. or its allies. But U.S. officials are loath to trust the Taliban to fulfill their obligations.

The prospects for Afghanistan's future are uncertain. The agreement sets the stage for peace talks involving Afghan factions, which are likely to be complicated. Under the agreement, 5,000 Taliban are to be released from Afghan-run jails, but it's not known if the Afghan government will do that. There are also questions about whether Taliban fighters loyal to various warlords will be willing to disarm.

It's not clear what will become of gains made in women's rights since the toppling of the Taliban, which had repressed women and girls under a strict brand of Sharia law. Women's rights in Afghanistan had been a top concern of both the Bush and Obama administration, but it remains a deeply conservative country, with women still struggling for basic rights.

There are currently more than 16,500 soldiers serving under the NATO banner, of which 8,000 are American. Germany has the next largest contingent, with 1,300 troops, followed by Britain with 1,100.

In all, 38 NATO countries are contributing forces to Afghanistan. The alliance officially concluded its combat mission in 2014 and now provides training and support to Afghan forces.

The U.S. has a separate contingent of 5,000 troops deployed to carry out counter-terrorism missions and provide air and ground support to Afghan forces when requested.

Since the start of negotiations with the Taliban, the U.S. has stepped up its air assaults on the Taliban as well as a local Islamic State affiliate. Last year the U.S. air force dropped more bombs on Afghanistan than in any year since 2013.

Seven days ago, the Taliban began a seven-day "reduction of violence" period, a prerequisite to the peace deal signing.

"We have seen a significant reduction in violence in Afghanistan over the last days, and therefore we are also very close to the signing of an agreement between the United States and the Taliban," NATO Secretary General Jens Stoltenberg said Friday in Brussels.

He was in Kabul on Saturday for a separate signing ceremony with Afghan President Ashraf Ghani and U.S. Defence Secretary Mark Esper. That signing was intended to show continuing NATO and U.S. support for Afghanistan.

"The road to peace will be long and hard and there will be setbacks, and there is a risk always for spoilers," Stoltenberg said. "But the thing is, we are committed, the Afghan people are committed to peace, and we will continue to provide support."