The PM says terror has been cut and human rights helped, but Labour accuses him of “staggering complacency”.
Boris Johnson has said Nato’s “core mission” in Afghanistan has “succeeded”, with the country being largely cleared of al-Qaeda terrorists.
The prime minister said allied forces had also ensured better education, women’s rights and free elections.
The UK Parliament has been recalled from its summer break for a debate on Afghanistan, but no vote is expected.
The Taliban have taken control of the country after US President Joe Biden’s decision to withdraw troops.
Labour leader Sir Keir Starmer said there had been “staggering complacency from our government about the Taliban threat”.
But he argued that the “sacrifice” made by UK troops in Afghanistan since the 2001 invasion had not been “in vain”.
Efforts are continuing to evacuate UK and other foreign citizens from Afghanistan, as the Taliban continue to strengthen their grip, with many people still stranded at Kabul airport.
And the UK has agreed to take in up to 20,000 refugees over the next few years amid efforts to avert a humanitarian crisis.
Speaking to a packed House of Commons, Mr Johnson said: “It would be fair to say that the events in Afghanistan have unfolded and the collapse has been faster than even the Taliban themselves predicated.
“What is not true is to say the UK government was unprepared or did not foresee this.”
The prime minister promised to work to get UK nationals stuck in Afghanistan home “as soon as possible”, adding that the Taliban were currently “allowing that evacuation to go ahead”.
“We will be doing everything to support those who have helped the UK mission in Afghanistan and investing everything we can to support the wider area around Afghanistan – and to do everything we can to avert a humanitarian crisis,” he added.
Amid frequent interventions from MPs, Mr Johnson said Nato forces had “succeeded in our core mission” of ridding Afghanistan of al-Qaeda operatives following the invasion of the country in 2001.
Mr Johnson said the UK and its allies would not, and should not, immediately recognise the Taliban regime – and that Afghanistan’s rulers, who have promised to observe human rights, must be judged on “actions rather than words”.
“At this bleak turning point we must help the people of Afghanistan determine the best of all possible futures,” he added.
The UK government has said it will allow up to 20,000 Afghans displaced by the crisis to resettle over the next few years, including 5,000 this year.
Women, girls and religious minorities most at risk from the Taliban will be prioritised, Home Secretary Priti Patel has said.
But Labour called for a “more urgent plan of action”, arguing that the scheme did not “meet the scale of the challenge”.
The House of Commons debate on Afghanistan is expected to last until about 17:00 BST.
The House of Lords is also sitting, from 11:00 BST, to discuss the situation.
Chief of the Defence Staff General Sir Nick Carter told BBC Radio 4’s Today programme that UK forces were “collaborating with the Taliban on the ground” to ensure stability and safety while evacuation efforts continue.
He added that the UK hoped to extract 1,000 people on Wednesday and that and seven planes were being sent to Kabul.
On Tuesday night an RAF plane carrying UK nationals and Afghans landed at RAF Brize Norton in Oxfordshire.
The Taliban have been advancing across Afghanistan over the past few months, but their progress accelerated after Mr Biden announced the withdrawal of his country’s troops.
The Taliban’s leaders have returned to Kabul from exile in Qatar, with a spokesman promising that women will be given rights in line with Islamic law.