The European Court of Justice has ruled the UK can cancel Brexit without the permission of the other 27 EU members, the BBC reports.
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.
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.