Afghanistan's approval Tuesday of a continued U.S. and NATO troop presence gives the Pentagon at least two more years to train Afghan troops and conduct targeted strikes against Taliban insurgents who have stepped up attacks in key parts of the country.
Signing the security agreement was one of the first acts of Afghan President Ashraf Ghani's new government, and is likely to help repair Kabul's long-strained relations with Washington.
"I assure all Afghans that this agreement is in our national interest," Ghani, who took office Monday, said after the signing ceremony at the presidential palace. Keeping foreign troops in Afghanistan would not be an "obstacle to peace," he said.
But the deal's tortuous path to approval reflects ambivalence among both U.S. and Afghan officials about continuing a 13-year military relationship that began with a U.S.-led invasion after the Sept. 11 attacks.
The joint effort has brought relative stability to much of Afghanistan. But the insurgency is undefeated and even resurgent in parts of the east and south.
President Obama has approved keeping 9,800 U.S. troops in Afghanistan after the end of the year to continue training, advising and equipping Afghan soldiers and police, and to carry out counter-terrorism operations against what Obama called the remnants of Al Qaeda.
In a statement, Obama said the accord would allow the U.S. and Afghanistan "to cement an enduring partnership that strengthens Afghan sovereignty, stability, unity and prosperity, and that contributes to our shared goal of defeating Al Qaeda and its extremist affiliates."
An additional 2,000 soldiers from other NATO countries are also due to remain.
Senior U.S. officials said Tuesday that it was unclear how much military assistance Afghanistan will continue to receive, and for how long.
The Obama administration has not decided whether it will continue to assist the Afghan army with military capabilities that it lacks, such as air cover from U.S. warplanes, evacuation of Afghans wounded on the battlefield, and intelligence and surveillance, usually provided by U.S. drones.
Providing such capabilities "is still a matter of discussion," said a senior State Department official, who requested anonymity to discuss internal administration deliberations.
The Pentagon plan calls for positioning the 9,800 U.S. troops at as many as nine bases in eastern and southern Afghanistan and around Kabul, the capital, officials said.
About 2,000 Americans would carry out counter-terrorism operations and the rest would train and advise Afghan forces, officials said.
But the force would soon shrink. Obama wants a maximum of 6,000 troops by the end of 2015, and 1,000 by the end of 2016. That gives the Pentagon a relatively short period to continue training Afghan soldiers and police, officials conceded.
Fearing that security could worsen if the U.S. pulls out too quickly, Pentagon officials hope the White House will ease the drawdown requirements over the next year, rather than face the possibility of having to send military forces back, as has happened in Iraq.
U.S. officials also are unsure whether North Atlantic Treaty Organization allies who have pledged to provide troops for the post-2014 mission will send the forces they promised, especially now that some of those countries have joined the airstrikes or are otherwise focused on Islamic State militants in Iraq.
The biggest question mark is Turkey, which has pledged to help train and advise Afghan troops around Kabul, but has not yet approved sending the troops. Italy and Germany are expected to lead the NATO training effort in western and northern Afghanistan.
But the delay in getting Afghan approval means some European governments may not be able to meet the timetable, officials said.
The U.S. has 33,000 troops in Afghanistan; many European countries that were expected to join the post-2014 mission already have pulled out most of their forces.
At least as important to Ghani's government is aid from Washington. Now that the deal has been signed, officials said, more than $5 billion a year for the Afghan military and nearly $2 billion in civilian aid are likely to continue to flow, but steadily diminish.
The security agreement was to have been signed last year after a loya jirga, or grand assembly of influential Afghans, approved the text. But then-President Hamid Karzai refused, arguing that U.S. forces continued to raid homes of noncombatants, causing civilian casualties.
Opposition to letting U.S. troops stay is especially strong in the southern province of Kandahar, where Army Staff Sgt. Robert Bales killed 16 villagers in a 2012 rampage, one of the worst cases of civilian killings of the war.
A U.S. military court sentenced Bales to life in prison, angering many in Kandahar who thought his crimes warranted the death penalty.