The European Court of Justice has ruled the UK can cancel Brexit without the permission of the other 27 EU members.
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.”
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.
The 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.
The court said the UK would be able to stay on the same terms it has now – so it would not be forced to join the euro or the Schengen area – where there are no passport controls between countries.
But the decision to stay 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.
Scottish Green MSP Ross Greer – one of the politicians involved in the case – said: “This is a massive moment at the start of a vital week, pointing to a clear way out of the Brexit mess.”
And the SNP’s Alyn Smith, who was also involved in the case, said: “A bright light has switched on above an exit sign.”
Jolyon Maugham QC, director of the Good Law Project which took the case to the court, said that the ruling was “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.
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”.
But 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.”
Foreign Secretary Jeremy Hunt told the BBC people would be “shocked and very angry” if any government delayed leaving the EU and it was “certainly not the intention of the government”.
Brexiteer Tory Jacob Rees-Mogg hailed the decision as the right one but said it would not affect Tuesday’s vote without a U-turn from the government.
“I think this government would find it very difficult to remain the government if it went away from what it said in its manifesto and the referendum result,” he told LBC.
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.