And yet, the war that began as America's response to 9/11 grinds on, as nearly 10,000 U.S. troops train and advise the Afghan army and police, hopeful that at some point the Afghans can stand on their own against the Taliban — or better, that peace talks will end the insurgency.

A look at the war Trump inherits from President Barack Obama, what U.S. troops are doing and why the outlook is so clouded.

THE U.S. MISSION

Recommended Stories For You

While Obama was a longtime critic of the Iraq war, he always cast the Afghanistan fight as vital.

Shortly after taking office in 2009, Obama looked to fix what he saw as U.S. failures in Afghanistan and Pakistan. He tripled troop levels in Afghanistan, but the surge did not force the Taliban to the negotiating table. Pakistan remains a sanctuary for the Taliban.

In December 2014, the U.S. ended its combat role in Afghanistan, but there will be at least 8,400 troops there when Trump takes office.

American troops and their coalition partners perform two tasks: The first, Operation Resolute Support, is to train and advise Afghan forces fighting the Taliban. The second, Operation Freedom's Sentinel, is to hunt down and kill al-Qaida militants as well as those affiliated with the Islamic State and other groups using the country as a hideout and potential launching pad for attacks.

"The interests we are pursuing here are clear and enduring," Defense Secretary Ash Carter said during a visit Friday. He cited the goals of preventing another 9/11-type attack on America and helping Afghanistan attain enough stability to remain a long-term security partner.

The U.S. performs its counterterror work in Afghanistan in two ways. First, it goes after al-Qaida and Islamic State operatives as a U.S.-only mission. Gen. John Nicholson, the top U.S. commander in the country, said last week that U.S. special operations forces have conducted 350 such missions in 2016 — an average of nearly one per day. These killed or captured nearly 50 leaders and other members of al-Qaida, he said.

Secondly, U.S. forces operate with Afghan special forces in hunting Islamic State fighters; these operations have killed the top 12 IS leaders in Afghanistan, Nicholson said.

He said that of the 98 militant groups designated by the U.S. as terrorist organizations, 20 are in Afghanistan, the world's highest concentration. That alone says much about the inconclusive — some would say failed — outcome of Obama administration's efforts.

Nicholson said Friday the remnants of al-Qaida, the group whose 9/11 attacks were the reason the U.S. invaded, still "has the intent" to attack America.

THE OUTLOOK

Nicholson and many U.S. generals who preceded him see reason for hope in the country. They point to modest progress against corruption and expanded opportunities for women.

He said he is confident the Afghan army, which suffered heavy losses in 2016, will continue to improve.

"It was a tough year," he said. "They were tested. They prevailed."

His predecessor, retired Gen. John Campbell, says the Afghans deserve continued support.

"The Afghan government is now taking on the Taliban more so than ever before," he said Friday in an email exchange.

Some analysts, however, worry that the Obama administration missed opportunities to improve security and strengthen the government.

Frederick W. Kagan, a military historian and director of the Critical Threats Project at the American Enterprise Institute, says security has deteriorated despite U.S. efforts to build up the army and police.

"If that's not good," he said of Afghan security, "nothing else matters. And it's not good."

Kagan says Obama is leaving his successor a worrisome situation.

"We're sliding toward the collapse of this government and potentially a renewal of the civil war," he said.

TRUMP'S WAR

Trump will not have an easy time disentangling the U.S. military from Afghanistan, short of an unlikely decision to simply walk away. He has said little about the country but has called broadly for an end to "nation-building" efforts.

Michael Flynn, the retired Army lieutenant general who will be Trump's national security adviser, sees Afghanistan as part of a broader war the U.S. must fight for generations.

"We defeated al-Qaida and the Iranians in Iraq, and the Taliban and their allies in Afghanistan. Nonetheless, they kept fighting and we went away," he wrote in his 2016 book, "Field of Fight." "Let's face it: Right now we're losing, and I'm talking about a very big war, not just Syria, Iraq and Afghanistan. We're in a world war against a messianic mass movement of evil people, most of them inspired by a totalitarian ideology: radical Islam."

Trump's choice to lead the Pentagon, retired Marine Gen. James Mattis, is a veteran of combat in Afghanistan. He has written that the U.S. devotes too few resources, guided by too little strategic clarity, to Afghanistan. But how that translates into action by the next White House is unclear.