The head of MI6 has warned that the Islamic State group is reorganising for more attacks despite its military defeat in Syria.
Alex Younger, the UK's intelligence chief, also told of his concern about jihadists returning to Europe with "dangerous" skills and connections.
They should expect to be investigated and possibly prosecuted, he said.
His comments come after Shamima Begum, a teenager who ran away to join IS, said she wants to return to the UK.
Ms Begum, now aged 19 and pregnant with her third child, said she had no regrets about travelling to Syria in 2015 but wanted to have her baby in Britain.
Mr Younger told the Munich Security Conference that so far the return of IS militants had proved a "completely manageable problem", but he warned that it was complex and unpredictable.
"We are very concerned about this because all experience tells us that once someone has put themselves in that sort of position they are likely to have acquired the skills and connections that make them potentially very dangerous," he said.
As IS faces the loss of its last strongholds in Syria, Mr Younger said it was likely to return to "asymmetric" terrorist attacks, rather than conventional warfare, and it would be harder for spies to penetrate the group now.
The organisation has proved itself "adept at inspiring attacks rather than directing them", he said.
He also warned of a "resurgence" of Al-Qaeda, the terror network responsible for the 9/11 attacks on the US which had been eclipsed by IS in recent years.
"It is definitely not down and out," said Mr Younger.
In wide-ranging comments, he also said:
- The UK should avoid using a single company for its new 5G mobile phone networks, after concerns that equipment from Huawei could be used for spying by the Chinese government
- Russian intelligence agencies, blamed for the poisoning of Sergei Skripal, are a "standing threat" and "very little is off limits" to them
- The UK's commitment to European security was "unconditional", despite Brexit, and that "lives had been saved" in the past year because of cooperation between Britain and other EU countries
Security chiefs could use a temporary exclusion order to block jihadists returning from Syria, such as Ms Begum, from entering the UK.
The controversial legal tool bars a British citizen from returning home until they have agreed to investigation, monitoring and, if required, deradicalisation.
by Frank Gardner, BBC News security correspondent
Britain's MI6 spy chief Alex Younger has chosen a rare appearance at this year's Munich Security Conference to deliver two messages.
These are that intelligence co-operation with key partners France and Germany does not end with Brexit, and secondly that the threat from the Islamic State group while diminished, has not disappeared with its caliphate.
His French and German counterparts shared a podium with him today but, being rather more media-shy, they declined to speak on the record.
The overall impression, though, was of Europe's three premier spy chiefs determined to present a united face against terrorism, Russian intervention, cyber attacks and any suspect technology from China.
Yet the shadow of Brexit still loomed over this gathering. Intelligence officials admit that without a formal agreement in place there is a risk that legal protocols may soon prevent the sharing of vital data, making counter-terrorism and the protection of populations that much harder.
Home Secretary Sajid Javid said he "would not hesitate" to prevent the return of IS supporters.
But Lord Carlile, a former independent reviewer of terrorism legislation, said Ms Begum would have to be accepted back into the UK if she had not become a national of any other country.
Under international law, it is not possible to render a person stateless.
Ms Begum told the Times that she had lost two children to illness and was scared of losing her unborn baby in the refugee camp where she was living - and has offered to "do anything required" to return home.
She was one of three schoolgirls, along with Kadiza Sultana, 16, and Amira Abase, 15, from Bethnal Green Academy in east London, who left the UK for Syria in February 2015.
Ms Begum escaped from Baghuz - IS's last territory in eastern Syria - two weeks ago.
Her husband surrendered to a group of Syrian fighters as they left, and she is now one of 39,000 people in a camp in northern Syria.
IS has lost control of most of the territory it overran, including its strongholds of Mosul in Iraq and Raqqa in Syria.
However, fighting continues in north-eastern Syria, where the Kurdish-led Syrian Democratic Forces (SDF) say they captured dozens of foreign fighters in recent weeks.