Millions more refugees could head for Europe if Britain and other Nato nations pull their troops out of Afghanistan too soon and the country collapses into disorder, Sir Michael Fallon has warned.
The Defence Secretary told an audience at the Munich Security Conference that if Afghanistan's fragile democracy failed "we here will feel the consequences, very directly".
He added "if it was right to go in, it has to be not right to leave before the job is done" during a discussion about whether Nato's 15-year mission in the war-torn nation had been a success or a failure.
Sir Michael said: "If this country collapsed we here will feel the consequences, very directly. There could be three, four million young Afghan men sent out by their villages to migrate westwards.
"And they are heading here, they are heading for Germany or Britain.
"That could be the consequence if this entire country collapses."
In total 456 British forces personnel or MoD civilians were killed while serving in Afghanistan.
Troops lowered the flag at Camp Bastion in October 2015, ending combat operations in the country after 13 years, though some remain in training and support roles.
During the Munich event, Sir Michael was flanked by his French, Dutch, Canadian and Turkish counterparts, as well as retired US admiral Jim Stavridis, the former Nato supreme allied commander Europe.
As well as a risk of a migrant influx Sir Michael warned there was still a risk from "transnational terrorist groups", adding: "That is why we went in in the first place - those transnational terrorist groups are still there and they still pose a threat."
He also said Nato should also act to protect its values, saying: "This is a democracy that we helped to establish.
"Seven million people voted in elections for a new future for Afghanistan, voted to choose a government, however fragile it is at the moment.
"That government has asked for our help and my view is we should stay with it until, as long as we can, until that job is done."
Earlier this month Armed Forces Minister Mike Penning told MPs Britain may increase its military presence in the country.
Giving evidence to the Commons Defence Committee, Mr Penning described the security situation in the war-torn country as "difficult", and joked he was "probably going to get shot" for revealing more personnel may be sent there.
He told MPs: "We have no plans to draw-down, actually there is a possibility that we might uplift because of what we are being asked to do.
"I have not been formally asked, but I might as well be honest with the committee, that's a possibility."