More than 2,200 US troops have been killed and hundreds of billions of dollars spent since the US-led invasion in 2001.

The United States will stick with Afghanistan for years to come as a new American president takes over what is already America’s longest war, the head of the US military Ashton Carter said on Friday.

In a joint appearance in Kabul with Afghanistan’s president, Ashraf Ghani, Carter said the US cannot afford to give up on Afghanistan after more than 15 years of involvement, the deaths of more than 2,200 US troops, and the expenditure of hundreds of billions of dollars.

“The interests we are pursuing here are clear and enduring,” he said, citing the goals of preventing another September 11-type attack on American soil, and helping Afghanistan attain enough stability to remain a long-term security partner for the US and the West. The war began as a response to the 9/11 attacks.

Afghan Taliban hang university student in public

Carter was making his last planned trip to Afghanistan before handing over his Defense Department responsibilities to his successor. President-elect Donald Trump has nominated retired Marine General James Mattis for the post.

Trump has not said if or how he will alter the US course in Afghanistan, but has denounced what he calls US nation-building projects.

The US has about 10,000 troops in Afghanistan to train and advise Afghan security forces combating a resilient Taliban insurgency. US special operations forces are hunting down al-Qaeda and Islamic State of Iraq and the Levant (ISIL) fighters.

By US estimates, the Afghan government controls slightly less than two-thirds of the country’s population. The Taliban holds sway over about 10 percent, and the remainder of the population is “contested”.

Taliban offers ‘security’ for copper, gas projects

President Barack Obama had planned to reduce US troop numbers to about 1,000 by the time he left office in January, but he scrapped that approach in the face of Taliban gains.

James Dobbins, a former US special envoy for Afghanistan, said Afghanistan would not figure highly for Trump, given the fight against ISIL in Syria and Iraq.

This, Dobbins said, was likely to mean the number of American troops in Afghanistan would remain unchanged, at least in the short term.

Trump will inherit a challenging security situation in Afghanistan.

A number of provincial capitals have been under pressure from the Taliban, while Afghan forces have been suffering high casualty rates, with more than 5,500 killed in the first eight months of 2016.