Boris Johnson has insisted the UK is “not about to turn away” from Afghanistan, as he announced that most British troops have left the country following a two-decade long coalition battle against the Taliban.

The US decision in April to end what President Joe Biden called “America’s longest war” has prompted security concerns given the risk that a resurgent Taliban will seek to overturn the Afghan government.

Sir Alex Younger, former head of the Secret Intelligence Service MI6, warned earlier this month that it would be an “enormous mistake” for western allies to neglect Afghanistan because a strengthening of Islamist groups in the region would raise the terror threat to the UK. However, Britain could not have continued its operations in the country without US military support.

Addressing MPs on Thursday, the prime minister said that even though the majority of the UK’s 750 troops in Afghanistan have been pulled out, Britain would continue to use “every diplomatic and humanitarian lever” to bolster its ally.

“I hope no one will leap to the false conclusion that the withdrawal of our forces somehow means the end of Britain’s commitment to Afghanistan,” he said. “We are not about to turn away, nor are we under any illusions about the perils of today’s situation and what may lie ahead.”

Johnson paid tribute to the 457 UK personnel who died during the conflict, and hailed the fact that no terrorist attacks had been mounted against western targets from Afghanistan since 9/11 — the atrocity which prompted former US president George W Bush to deploy troops into the country 20 years ago.

But the departure of coalition forces comes as the Taliban is making new territorial gains, particularly in the north of the country. This week, more than 1,000 Afghan soldiers were reported to have fled across the border to Tajikistan after clashing with Taliban militants.

General Sir Nick Carter, head of the UK’s armed forces, said recent news from Afghanistan had been “pretty grim”.

He told reporters on Thursday that while he hoped that the Afghan government could continue to hold off the Taliban even without Nato support, or reach a political agreement, there was a “plausible” scenario of “state collapse”.

UK troops played a significant combat role in operations until 2014, and more recently were engaged in training the Afghan Security Forces and providing security in the capital. So far 5,000 Afghan cadets have graduated from the UK training facility, of whom more than 300 now hold senior positions in the Afghan military.

Britain is expected to leave a small number of troops behind to help protect diplomats in Kabul. The UK will also provide £100m of development assistance and £58m for Afghan defence.

Most European countries have already withdrawn military personnel, with Germany, Italy and Poland recently announcing that their troops had arrived home, while the US has taken out 90 per cent of its 2,500 forces.

Johnson told parliament that the international military presence in Afghanistan was “never intended to be permanent,” and that there “could never be a perfect moment” to withdraw.

Carter suggested the challenge for the 350,000-strong Afghan Security Forces is that they will no longer have access to air power support from the US-run Bagram air base that “gave them “the edge in the fight . . . with the Taliban”.

The general emphasised that the Nato-led coalition had made a positive contribution to the country, through strengthening local forces, opening schools and health clinics, and taking Islamists on “at the heart of the insurgency”.