KABUL, Afghanistan (AP) -- Afghanistan and the United States signed a security pact on Tuesday to allow U.S. forces to remain in the country past the end of year, ending a year of uncertainty over the fate of foreign troops supporting Afghans as they take over the fight against the Taliban insurgency.
Under the pact, along with a separate deal signed with NATO, about 10,000 American troops and several thousand more from other NATO countries will stay to train and advise Afghan forces, after the international combat mission ends Dec. 31.
Former Afghan President Hamid Karzai had refused to sign it despite U.S. threats of a full withdrawal in the absence of legal protections for American forces. U.S. officials have said that the delay in the deal's signing does not affect plans for next year.
President Ashraf Ghani Ahmadzai, who was sworn into office a day earlier, told a crowd assembled at the presidential palace in the capital Kabul for the signing ceremony that the agreement signaled a fundamental shift for the positive in the country's relations with the world.
"This agreement is only for Afghan security and stability," he said in comments broadcast live on state television. "These agreements are in our national interest. The Bilateral Security Agreement will pave the ground for Afghanistan to take control," he added.
President Barack Obama hailed what he called a "historic day in the U.S.-Afghan partnership that will help advance our shared interests and the long-term security of Afghanistan," according to a White House statement.
"This agreement represents an invitation from the Afghan government to strengthen the relationship we have built over the past 13 years and provides our military service members the necessary legal framework to carry out two critical missions after 2014: targeting the remnants of al-Qaida and training, advising, and assisting Afghan National Security Forces," it said.
More than a decade after U.S. forces helped topple the Taliban in the wake of the Sept. 11 attacks, Afghanistan is still at war with the Islamic militant group, which regularly carries out attacks, mainly targeting security forces.
Newly appointed Afghan national security adviser Mohammad Hanif Atmar and U.S. Ambassador James Cunningham signed the actual document. The second agreement allowing NATO troops to stay in the country was signed during the same ceremony.
With the new year, the new NATO mission in Afghanistan - called "Resolute Support" - will work to train, advise and assist Afghan forces. The force of around 12,000 will include American troops and forces from other NATO countries. Some of the 10,000 U.S. troops that will remain in Afghanistan will operate under an American command separate from the NATO mission.
"We remain committed to help finance the Afghan security forces through 2017, to help Afghanistan to further strengthen its institutions, and to further develop our political and practical cooperation with Afghanistan," NATO Secretary General Anders Fogh Rasmussen said in a statement.
Afghan Government Chief Executive Abdullah Abdullah, who has assumed a post akin to prime minister after signing a power-sharing agreement with Ghani Ahmadzai, also welcomed the security deal.
"It has been signed after very careful considerations," he said, adding that "the BSA is not a threat to our neighbors. It will help strengthen peace and stability in the region."
Abdullah and Ghani Ahmadzai struck the power-sharing agreement earlier this month after a prolonged dispute over alleged voting fraud in June's presidential runoff. Karzai's refusal to sign the security pact, and the prolonged uncertainty over who would succeed him, had delayed the signing.