Ken McCallum believes it will be "challenging" to stop potential threats without "having our own forces on the ground".
The security agency's boss made the comments after Defence Secretary Ben Wallace is said to have indicated, during a visit to Washington, his disappointment at President Joe Biden's decision to withdraw US forces, saying the rest of the international community had little choice but to follow suit.
Mr Wallace reportedly said the UK is willing to work with the Taliban if it enters government in Afghanistan.
The militants will meet with representatives of the Afghanistan government this week as Taliban fighters surge through district after district, taking control of large parts of the country amid the withdrawal of US and international forces.
Effect of 20 years of effort
Mr McCallum said: "In Afghanistan, 20 years of dedicated effort have had a profound effect: the Al Qaida terrorist infrastructure we faced at scale in 2001 is long since gone."
He also paid tribute to the military "whose heroism and sacrifice achieved those vital gains".
"As US and NATO forces now withdraw, terrorists will seek to take advantage of opportunities – including propaganda opportunities – to rebuild," he said.
In his annual address, Mr McCallum added: "As we seek to illuminate potential threats and take disruptive action, we will no longer have the advantages or the risks of having our own forces on the ground.
"This form of counter-terrorism is not new to us – it's how we've always operated in Somalia, for instance; but from our experience, we know it is challenging."
What are the threats of the future?
Asked whether there was a risk this could pose further terrorist threats for the UK, Mr McCallum said some might seek to re-establish "training facilities".
Although he added, it "doesn’t automatically follow" that they would then go on to "direct attacks, terrorist attacks against the UK", for example, it is "clearly a possibility" to which we "must be alert".
He described Islamist extremist terrorism as still MI5's "largest operational mission" and a "potent, shape-shifting threat" while confirming that Syria remains the "overseas location with the greatest influence on the UK threat".
Mr McCallum said MI5 was also working to tackle "re-emerging extremist threats in Africa, principally in Somalia."
He told of the devastation those working at MI5 feel when terror attacks and other incidents occur but also described how this served as a "burning motivation".
"The most important response we can give is to do all in our power to reduce the risk of future attacks. We do not rest," he added.
Cover image: Two RAF Puma helicopters fly over Kabul, Afghanistan, as Op Toral draws to a close (Picture: MOD).