The security situation is still precarious in many parts of the country. Afghanistan's strategic landscape is changing as regional powers forge links with the Taliban and vie to outdo each other in what's being seen as a new "Great Game".
Fifteen years after the US-led intervention in Afghanistan, competition for influence - reminiscent of that rivalry between the Russian and British empires in the 19th and early 20th Centuries, and that during the Cold War in the 1980s - is intensifying, complicating an already precarious security situation.
Political cartoon depicting the Afghan Emir Sher Ali with his
"friends" the Russian Bear and British Lion (1878)
Suspicion and mistrust remain the biggest obstacle to stability in strategically-located Afghanistan, which has the potential to destabilise the wider region.
Pakistan, considered the main supporter of the Afghan Taliban, has been accused of playing a double game. But Afghan and Western officials as well as Taliban sources have also spoken about the Taliban's clandestine links with Iran for the past few years.
And recently it emerged that Russia's ties with the Taliban were warming too.
Soviet troops pulled out of Afghanistan in 1988 - Russia now has links with the Taliban
In December the top US commander in Afghanistan, Gen John Nicholson, criticised Russia and Iran for establishing links with the militants, which both countries have confirmed.
The US has also pursued contacts with the Taliban in recent years but those efforts have not brought peace. Several regional powers, most notably Russia and Iran, criticise the US and its allies for "failing" in achieving its original objectives of eliminating violent extremism and drugs in Afghanistan.
Three major factors have contributed to the shifting of regional alliances:
the emergence of so-called Islamic State in Afghanistan;
changes in the approach of the new Afghan government;
and tensions between the US and regional players such as Russia, China, Iran and Pakistan.
Fears over Islamic State
The emergence of IS in Afghanistan - the group announced the creation of its Khorasan Province branch in January 2015 - provided Russia and Iran with the opportunity to make "contacts" with the Taliban.
Army Gen. John Nicholson speaks at a news conference with US Defence Secretary Ash Carter, Friday 9 December 2016 at Bagram Air Base, north of Kabul, Afghanistan.
The US's decreasing military role in Afghanistan and a resurgent Taliban had contributed to creating a sense in regional capitals that Afghanistan's fate was up for grabs. The political infighting in the central government in Kabul also raised concerns about political stability both inside and outside the country.
Over the past two years, alarm in Russia and former Soviet Central Asian republics grew as militancy spread to northern Afghan provinces close to their borders as well as to China's Xinjiang region.
Conspiracy theories in Russia, Iran and China paint IS as an American or Western creation aimed at destabilising their countries.
The government says it is cracking down on IS, some of whose alleged members have been paraded by Afghan police
The emergence of IS posed a serious challenge to the supremacy of the Taliban but also encouraged Iran, China and Russia, who were fearful of IS expansion, to review their policies and open dialogue with the Taliban.
Russia's Taliban 'channels'
Softening its approach towards the Taliban is a dramatic and unexpected shift for Russia.
Moscow has for years opposed the Taliban, calling them terrorists, and supported the anti-Taliban "Northern Alliance" in the Afghan civil war of the 1990s.
But faced with a common enemy in the shape of IS, Russia has changed its mind.
In December 2015, a senior Russian diplomat declared that "the Taliban interest objectively coincides with ours" in the fight against IS and that his country and the Taliban "have channels for exchanging information".
Taliban sources also confirmed that the group's representatives met Russians inside Russia and "other" countries several times over the past two years.
But Moscow's current assertiveness in Afghanistan can also be seen as a tactic to put pressure on the US and to enhance its role and regional influence.
Taliban contacts with Russia and Iran might also help Pakistan to distribute and dilute the international pressure it is under for hosting the Afghan Taliban leadership.
Iran and the Taliban make up. Shared animosity towards IS has also brought the Sunni Taliban closer to their historic nemesis, Iran, a Shia powerhouse, whose clerical regime had previously viewed the Afghan Taliban as a major threat.
Iran and its allies have been fighting IS in Syria and Iraq
Like Russia, Iran supported the anti-Taliban groups in the 1990s. Tehran also co-operated with the US-led international coalition to topple the Taliban regime in late 2001. But, at the same time, Taliban sources say Iran sent them a message that it was willing to support them against the US.
When the Taliban insurgency gained momentum in Afghanistan, Iran publically supported the US-backed Afghan government but reportedly kept a link to the Taliban alive. Since the emergence of IS (which considers Shia to be infidels), the Tehran-Taliban relationship has deepened.
A delegation from the Afghan Taliban's political office in Qatar visited Iran in mid-May 2015 where the two sides discussed, among other things, ways to counter IS in Afghanistan.
The Taliban supreme leader, Mullah Akhtar Mansour, was reportedly on his way back from Iran when he was killed in a US drone strike in Pakistan's Balochistan province in May 2016.
Afghanistan's 'imbalanced' foreign policy
The foreign policy of the Afghan government established in September 2014 has also altered political calculations.
Hawks in Russia, Iran and China consider President Ashraf Ghani's government with suspicion and see it as too weak to deal with the multiple security challenges it faces.
They also view Mr Ghani as too close to the US compared with his predecessor, Hamid Karzai.
And some of Mr Ghani's decisions have raised eyebrows in regional capitals.
Afghan security forces have launched operations against both Taliban and IS militants
Soon after taking office, he said that improving relations with Pakistan was a top priority. While ignoring India, Pakistan's arch-rival but Afghanistan's traditional ally, the new president made several positive gestures to appease Islamabad. But that rapprochement ended within a year and Kabul and Islamabad reverted to hurling accusations at each other.
Mr Ghani then revived Afghanistan's close relationship with India and on a few occasions seemed to be taunting Pakistan while speaking in India.
His government also pledged support for the Saudi-led military coalition against Shia Houthi rebels in Yemen. That gesture was not received well in Tehran.
These rivalries underline the nature and scale of possible troubles ahead.
The Taliban as Trojan horse?
The Afghan Taliban had been largely dependent on their support base in Pakistan, a country where their leadership is allegedly living. Fears are now growing in Afghanistan that the Taliban are being used as a Trojan horse by state actors in three main ways:
to put pressure on the Afghan government and its US/Nato allies;
to increase the influence of individual countries;
and to outdo one another in a regional competition.
Taliban fighters carrying weapons cheers during a speech by their senior leader in the Shindand district of Herat province, Afghanistan. 27 May 2016.Image copyrightAP
Talks have not yet led to peace with the Taliban
The Taliban see their expanding regional portfolio and diplomatic push as evidence of their "legitimate struggle" - in some ways more important for them than material assistance.
The price the Taliban ask has generally been for these countries to help them rid Afghanistan of foreign forces. In return the Taliban offer the following assurances:
not to allow IS to establish a base in Afghanistan;
to prevent foreign militants from using Afghanistan against these states;
to keep their war focused on Afghanistan.
So where will a new 'Great Game' lead?
Most US military personnel have left Afghanistan - there is little appetite for more losses among the US public
Major regional players seem to have realised that they cannot rely on the US alone to sort out Afghanistan and stabilise the wider region. They are keen to make themselves much more relevant and are looking to play a more assertive role. They also insist that their "contacts" with the Taliban are aimed at promoting regional security.
Afghanistan has been the scene of foreign interventions for a long time. The British and Russian Empires jockeyed for control during the 19th and early 20th Centuries. In the 1980s the US-led Western alliance helped Pakistan provide weapons and funding to Afghan mujahideen fighting to end Soviet occupation.
Recent developments show the extent of a new "Great Game" taking shape.
And once again Afghan civilians are caught in the crossfire.
An artillery gun is air lifted out of a British base in Afghanistan by an American helicopter as the base is closed. 8 May 2014.Image copyrightMOD
The UK, one of the original 19th Century "Great Game" players, has once again pulled out of the country
The past few decades have shown that no country has the means to impose its will in Afghanistan on its own, but many actors have created disorder.
Because a big part of the chaos in Afghanistan is rooted in the wider region, the solution needs co-operation and a wider consensus. One positive outcome of the shifting regional alliances might be a more inclusive approach towards stabilising Afghanistan and its neighbourhood.
Many Afghans are hopeful that Russian leader Vladimir Putin and incoming US President Donald Trump will improve bilateral relations, with a positive impact on the situation in Afghanistan.
For many decades during its recent past, when it was left alone, Afghanistan was one of the most peaceful and stable countries. History shows that what Afghanistan needs is less foreign interference, not more of it.
By Dawood Azami ,BBC World Service, Kabul
…. The Great Game Strategic rivalry between the British and Russian Empires…, in which outside powers struggle for control of Afghanistan, is alive and well…
Afghanistan: The Great Game - A Personal View by Rory Stewart …Rory Stewart tells the story of foreign intervention in Afghanistan from the 19th century to the present day… Afghanistan: The Great Game - A Personal View by Rory Stewart: Episode 2 …Rory Stewart tells the story of the Soviet invasion of Afghanistan in the twentieth century, and its parallels with the American-led coalition's intervention today. He explains that, quite contrary to popular understanding, the Soviets…
Afghanistan: The Great Game - A Personal View by Rory Stewart: Episode 1 … became known as "The Great Game". Afghanistan was perceived by Victoria