Afghan president-elect Ashraf Ghani Ahmadzai is seen before speaking at an event in Kabul September 22, 2014.CREDIT: REUTERS/OMAR SOBHANI

(Reuters) - Afghanistan's next president, Ashraf Ghani, is expected to sign legal documents within 24 hours of taking office next week allowing foreign troops to stay in his country beyond 2014, a senior NATO diplomat said on Tuesday.

NATO plans to end combat operations in Afghanistan at the end of this year and to leave a smaller training and advisory force in the country from next year to assist Afghan security forces in their fight against a resurgent Taliban insurgency.

But those plans were called into question first by outgoing President Hamid Karzai's refusal to sign documents establishing a legal basis for U.S. and other NATO troops to stay on and then by a long deadlock over the election of a new president amid allegations of fraud.

Ghani, a former finance minister, was named president-elect on Sunday after he signed a deal to share power with his opponent, ending months of turmoil and removing an obstacle to the signing of a bilateral security agreement (BSA) with the United States and a "status of forces agreement" (SOFA) with NATO.

"Ghani ... will be inaugurated next Monday, the 29th, and we anticipate that within about 24 hours of inauguration he will sign the BSA and we hope the SOFA as well," the senior NATO diplomat said.

"So that we would potentially next Tuesday be in a position where all the pieces have fallen in place for NATO to do its post-2014 mission," he said, speaking to reporters on condition of anonymity.

The NATO-led International Security Assistance Force has around 41,000 troops in Afghanistan, nearly three-quarters of them American.

From next year, about 12,000 foreign troops, including about 8,000 Americans, are likely to stay on as part of a NATO-led training and advisory mission while some 1,800 Americans will conduct counter-terrorism missions.

NATO diplomats had said that if the deadlock over the Afghan election persisted into October, NATO could be forced to start pulling out all of its troops from Afghanistan because of the risk they would not have the legal certainty to continue operating there beyond the end of this year.

The United States intervened in Afghanistan to deny al Qaeda a sanctuary after the Sept. 11, 2001, attacks. NATO -- the North Atlantic Treaty Organization -- took a peacekeeping role in Kabul in 2003, gradually extending it throughout the country.