The European Court of Justice has ruled the UK can cancel Brexit without the permission of the other 27 EU members, report agencies.
The ECJ judges ruled this could be done without altering the terms of Britain’s membership.
A group of anti-Brexit politicians argued the UK should be able to unilaterally halt Brexit, but they were opposed by the government and EU.
The decision comes a day before MPs are due to vote on Theresa May’s deal for leaving the EU.
MPs are already widely expected to reject the proposals during a vote in the House of Commons on Tuesday night.
BBC Brussels correspondent Adam Fleming said the ruling made staying in the EU “a real, viable option” and that may “sway a few MPs” in the way they vote.
But he said “a lot would have to change in British politics” to see the UK remain in the EU, with Mrs May and the government having to change its mind to make it a “political reality”.
A senior ECJ official – the advocate general – said last week he agreed the UK should be able to change its mind about leaving.
His opinion was not legally binding, but the court tends to follow his advice in the majority of cases and it has broadly done so in this ruling.
Thea statement from the ECJ said the ability for a member state to change its mind after telling the EU it wanted to leave would last as long as a withdrawal agreement had not been entered into, or for the two-year period after it had notified the bloc it was leaving.
If that two-year period gets extended, then a member state could change its mind during that extra time too.
But the court said the decision must “follow a democratic process”, so in the UK’s case, it would have to be approved by Parliament.
The member state would then have to write to the EU to notify them of the “unequivocal and unconditional” decision.
The ECJ said it made the ruling to “clarify the options open to MPs” ahead of voting on Mrs May’s deal.
The campaigners hope the victory in their legal case will increase the chances of Brexit being called off completely, potentially through another referendum.
Jolyon Maugham QC, director of the Good Law Project which took the case to the court, said the ruling was “the biggest upset since the First Book of Samuel and arguably the most important case in modern domestic legal history”.
“It is up to MPs to remember what they came into politics for and find the moral courage to put the country’s interests before private ambition,” he added.
Environment Secretary Michael Gove, a prominent Brexiteer, told BBC Radio 4’s Today programme those calling for a second vote were “people who never accepted that first vote, who didn’t accept that democratic mandate and who want to overturn it”.
“We don’t want to stay in the EU. We voted very clearly, 17.4 million people sent a clear message that we want to leave the European Union, and that means also leaving the jurisdiction of the European Court of Justice,” he added.
“So, this case is all very well, but it doesn’t alter the referendum vote or the clear intention of the government to make sure that we leave on 29 March.” The first minister of Scotland, Nicola Sturgeon – who backed Remain – said the ruling meant it was “now open to the House of Commons” to extend Article 50 to allow time for another vote.
And Lib Dem Brexit spokesman Tom Brake tweeted that it was the “best news possible” and said it was now “full steam ahead for a People’s Vote”.
The ECJ ruling comes despite the EU warning that it would set a dangerous precedent by encouraging other countries to announce they were leaving in an attempt to secure better membership terms, before cancelling their withdrawal.
The UK government’s lawyers also argued that the case was purely hypothetical as “the UK does not intend to revoke its notification” and those politicians behind it wanted to use the case as “political ammunition to be used in, and to pressure, the UK Parliament”.
The case was initially taken to the Court of Session in Edinburgh, which ultimately agreed to pass it to the ECJ.
Two attempts by the UK government to appeal against the referral to the European court were rejected, and the case was heard by all 27 ECJ judges last month.