Qatar and Turkey become Taliban's lifeline to the outside world

The Taliban's celebratory gunfire crackled over Kabul as the West pulled out this week.

But militancy alone is likely to leave the Taliban on its own - globally isolated, with millions of Afghans facing an even more uncertain future.

The world's powers are now scrambling to exert influence amid the return of the country's Islamist rulers. And in the process two nations from the Arab and Muslim world have been emerging as key mediators and facilitators - Qatar and Turkey.

Both are capitalising on a recent history of access to the Taliban. Both eye opportunities. But both are taking a gamble too - which could even stoke old rivalries further afield, in the Middle East.

Officials in the small, gas-rich state of Qatar in the Gulf have provided the lifeline for countries trying to exit.

"No-one has been able to do any major evacuation process out of Afghanistan without having a Qatari involved in some way or another," explains Dina Esfandiary, a senior adviser at the International Crisis Group, a think tank which studies global conflict.

"Afghanistan and the Taliban will be a significant victory for [Qatar], not just because it will show that they're able to mediate with the Taliban, but it makes them a serious player for the Western countries that are involved," she told the BBC.

As Western countries fled Kabul, the diplomatic value of these contacts surged. The Twitter feed of Qatar's Foreign Ministry spokeswoman, Lolwah Alkhater, reads like a conveyer belt of retweeted tributes from world powers.

"Qatar… continues to be a trusted mediator in this conflict," she wrote earlier this month.

But bridging a trail to the Taliban may still contain risks for the future, including the capacity to aggravate one of the Middle East's fault lines. Turkey and Qatar are closer to the region's Islamist movements, which frequently creates tension with powers like Egypt, Saudi Arabia and the United Arab Emirates, who see such groups as an existential threat.

If the two states are strengthened by doing the world's diplomacy with the Taliban in South Asia, could the ripples travel to the Middle East?

Dina Esfandiary says the Taliban's surge back to power constitutes a renewed swing towards Islamism - a political ideology that seeks to reorder government and society in accordance with Islamic law - but she says for now it remains contained to South Asia.

"It is for Afghanistan, it doesn't mean it's the case for the [Middle East]. Over the course of the last 10 years the region has gone back and forth non-stop between Islamist groups and non-Islamist groups," she says.