Shamima Begum, who left the UK for Syria to join the Islamic State group as a teenager, will not be allowed to return and fight her citizenship case, the Supreme Court has ruled.
The court said in a unanimous ruling that her rights were not breached when she was refused permission to return.
Ms Begum, 21, wants to come back to challenge the home secretary's decision to remove her British nationality.
She is currently in a camp controlled by armed guards in northern Syria.
Ms Begum was 15 when she and two other east London schoolgirls left the UK in February 2015 and travelled to Syria to join the Islamic State group.
In 2019, the then-Home Secretary Sajid Javid stripped Ms Begum of her citizenship on national security grounds.
Last July, the Court of Appeal ruled that the only fair way forward was to allow her into the UK because she could not effectively appeal against the decision from the camp in northern Syria.
The Home Office subsequently appealed to the Supreme Court to reconsider the Court of Appeal's judgement, arguing that allowing her to return to the UK "would create significant national security risks".
On Friday, Lord Reed, president of the Supreme Court, said the government had been entitled to prevent Ms Begum from returning to the UK.
Announcing the ruling, Lord Reed said: "The Supreme Court unanimously allows all of the home secretary's appeals and dismisses Ms Begum's cross-appeal."
He said the Court of Appeal's judgment "did not give the home secretary's assessment the respect which it should have received" given the role's "responsibility for making such assessments" and accountability to parliament.
Lord Reed added the Court of Appeal had "mistakenly believed that, when an individual's right to have a fair hearing... came into conflict with the requirements of national security, her right to a fair hearing must prevail."
He said the right to a fair hearing did "not trump all other considerations, such as the safety of the public".
Shamima Begum says she wants forgiveness - but all she's achieved after two years of battles over her citizenship is legal limbo.
That's the extremely unusual outcome of her epic struggle against the home secretary over whether she can still call herself British.
It is the role of judges and the courts to uphold the rule of law - and protect the universal right that each of us has to make our case fairly in court.
But, when it comes to matters of national security - threats to the nation - judges won't tell ministers that their assessment is wrong unless they have heard compelling evidence to prove it.
In the Begum case, that means she is at the heart of an imperfect world of her own making.
She is stuck, with no right to return under the law.
But, at the same time, her lawyers maintain she can't take part in her own case to have her citizenship returned because of the uniquely dangerous situation she is in.
Other people banned from the UK have found a way to take part in appeals from overseas - but the camp she is in won't even let her lawyers visit.
And so the highest court in the land says her entire case must now be paused until she can find some way of taking part.
And perhaps that will never, ever happen.
Lord Reed said the appropriate answer was not to force the government to bring Ms Begum back to the UK - but to pause her legal fight over citizenship until she is in a safer position to take part in her appeal.
He added: "That is not a perfect solution, as it is not known how long it may be before that is possible. But there is no perfect solution to a dilemma of the present kind."
The current home secretary, Priti Patel, said the Supreme Court's judgement had "reaffirmed the home secretary's authority to make vital national security decisions".
She added: "The government will always take the strongest possible action to protect our national security and our priority remains maintaining the safety and security of our citizens."
Who is Shamima Begum?
Ms Begum was born in the UK to parents of Bangladeshi heritage.
When she was 15, she and two other schoolgirls left the UK for Syria to join IS.
Ms Begum travelled via Turkey to IS headquarters in Raqqa, where she married a Dutch recruit.
She lived under IS rule for more than three years, and was found, nine months pregnant, in a Syrian refugee camp in February 2019.
The baby later died of pneumonia and Ms Begum said she had previously lost two other children.
You can read more here.
Mr Javid also welcomed the ruling, saying any "restrictions of rights and freedoms" faced by Ms Begum were a "direct" result of her "extreme" actions.
He said: "There are no simple solutions to this situation but any restrictions of rights and freedoms faced by this individual are a direct consequence of the extreme actions that she and others have taken, in violation of government guidance and common morality."
Liberty, the human rights group which intervened in Ms Begum's case, said the latest ruling sets "an extremely dangerous precedent".
Rosie Brighouse, a lawyer with Liberty, said: "The right to a fair trial is not something democratic governments should take away on a whim, and nor is someone's British citizenship.
"If a government is allowed to wield extreme powers like banishment without the basic safeguards of a fair trial it sets an extremely dangerous precedent.
"The security services have safely managed the returns of hundreds of people from Syria but the government has chosen to target Shamima Begum."
Maya Foa, director of the human rights group Reprieve said preventing Ms Begum from entering the UK remained "a cynical ploy to make her someone else's responsibility".
"Like many of its European counterparts, the UK is more than capable of bringing home British detainees in Syria, many of whom left as teenagers after being trafficked or groomed online.
"Abandoning them in a legal black hole - in Guantanamo-like conditions - is out of step with British values and the interests of justice and security."