He described the decision to withdraw troops from the country as "tragic, dangerous and unnecessary".
Mr Blair, who sent troops into Afghanistan 20 years ago, said UK involvement in Afghanistan was not a "hopeless endeavour" despite the Taliban takeover.
And the sacrifice made by British troops "was not in vain", he added.
Mr Blair said achievements in the country over the past 20 years - including a generation growing up without Taliban rule - was a "good cause" that "matters today".
Speaking to broadcasters, the former Labour leader shared concerns, not only for the Afghan people who he said stood to lose out, but also for the security of Western countries.
He said the Taliban "will give protection and succour to Al Qaeda - you've got Isis trying to operate in the country at the same time".
"You look round the world and the only people really cheering this decision are the people hostile to Western interests," he added.
In his online article, his first statement since Kabul fell to the Taliban last week, Mr Blair said the decision to withdraw was made "in obedience to an imbecilic political slogan about ending 'the forever wars'".
Mr Blair said Britain had a "moral obligation" to stay in Afghanistan until "all those who need to be are evacuated".
He wrote on his website: "We must evacuate and give sanctuary to those to whom we have responsibility - those Afghans who helped us and stood by us and have a right to demand we stand by them."
This should not be done "grudgingly but out of a deep sense of humanity and responsibility", he added.
On Sunday the Ministry of Defence said seven Afghan civilians had died in the chaotic crowds outside the city's international airport.
The US has a planned deadline of 31 August for withdrawal - but President Biden has said troops may stay past this date to help with evacuations.
Mr Blair admitted mistakes had been made over Afghanistan, but "the reaction to our mistakes has been, unfortunately, further mistakes". He said while "imperfect", the "real gains over the past 20 years" were now likely to be lost.
He said the Afghan economy was now three times larger than when the UK invaded the country alongside the US in 2001 and some 200,000 Afghans went to university this year - including 50,000 women.
The withdrawal would have "every jihadist group around the world cheering", he said.
Russia, China and Iran will take advantage, he said, adding: "Anyone given commitments by Western leaders will understandably regard them as unstable currency."
Peter Galbraith, former UN deputy special representative for Afghanistan, said all the coalition partners bore responsibility for the chaos unfolding.
"In terms of what was imbecilic, frankly it was the strategy that was followed for 20 years, which was to try to build a highly centralised state in a country that was as diverse - geographically and ethnically - as Afghanistan, and to engage in a counterinsurgency strategy without a local partner and the local partner was corrupt, ineffective, illegitimate," he said.
He added that coalition partners "never seriously tried to address the corruption that was prevalent from the top", acquiescing in "fraudulent" Afghan elections, and trying to fit facts into a predetermined strategy, "rather than having a strategy that was based on the facts".
President Biden has vowed that "any American who wants to come home, we will get you home", but has described the evacuation as one of the "most difficult airlifts in history".
Mr Blair's intervention comes as shadow foreign secretary Lisa Nandy has urged her government counterpart Dominic Raab to step up efforts to get British and eligible Afghans to the UK.
She said she had heard of people being beaten, shot at or raped while trying to get documentation in Kabul.
The Foreign Office said it was trying to get people out as fast as possible, with more than 3,000 people having been evacuated from the country since last Sunday.
In an article in the Mail on Sunday, Defence Secretary Ben Wallace said the West's exit from Afghanistan was "unedifying" and would have "consequences for us all for years to come".
He praised the British soldiers working at Kabul's airport for dealing with "unimaginable challenges - public order, overcrowding, searing heat and desperate people".
"Soldiers trained for war are instead holding babies and co-ordinating crowds," he wrote.
Mr Wallace said there was "no time to lose" to get people out of the country but added the US would have his complete support if it chose to push back the deadline for leaving.