European Union leaders and the British Prime Minister Theresa May have agreed to an extension to Brexit to avoid Britain from crashing out of the EU without a deal.
The extension allows Britain to delay its EU departure date until October 31, with a review to be held in June after a plea from Mrs May.
The last-minute deal was reached just one day before the existing deadline expired.
The EU leaders gave Mrs May more than the three months she had initially requested.
The late-night deal means Britain will not crash out of the bloc tomorrow and gives Mrs May time to build a parliamentary majority to back the withdrawal treaty she negotiated with the EU last year.
The British Parliament has repeatedly rejected a withdrawal deal negotiated with the EU, leading to the deadlock over Britain's long-awaited departure.
The 27 EU leaders agreed to Mrs May’s request for an extension during a summit in Brussels.
May still believes a Parliament vote is possible
Mrs May believes a June 30 deadline is enough time for Britain's Parliament to ratify a Brexit deal and pass the legislation needed for a smooth Brexit.
But British MPs have rejected her divorce deal three times, and attempts to forge a compromise with her political opponents have yet to bear fruit.
Mrs May addressed the EU leaders for more than an hour, before they met for dinner without her to decide Britain’s fate.
Many leaders said they were inclined to grant a Brexit delay, however French Prime Minister Emmanuel Macron had reservations after hearing Mrs May speak.
An official in the French President's office said the British leader had not offered "sufficient guarantees" to justify a long extension.
Mr Macron is concerned that letting Britain stay too long would distract the EU from other issues – notably next month's European Parliament elections.
‘Don’t waste this time’
Speaking after the talks, EU Chairman Donald Tusk said his "message to British friends" was "please do not waste this time".
"The course of action will be entirely in the UK's hands: they can still ratify the withdrawal agreement, in which case the extension can be terminated," he said.
The UK could also rethink its strategy or choose to revoke Article 50 and "cancel Brexit altogether".
"This extension is as flexible as I expected, and a little bit shorter than I expected, but it's still enough to find the best possible solution.
"Please do not waste this time."
European elections looming
Ms May said the UK would still aim to leave the EU as soon as possible.
Irish Taoiseach Leo Varadkar said the UK must now hold European elections in May, or leave on June 1 without a deal.
The PM had earlier told leaders she wanted to move the UK's exit date to June 30, with the option of moving that date forward again if she can get her withdrawal agreement ratified by Parliament.
Mrs May said if Parliament ratifies the withdrawal agreement in the first three weeks of May, the country would then not have to participate in European elections.
But until her deal is approved, the UK "will continue to hold full membership rights and obligations".
"I know there is huge frustration from many people that I have had to request this extension,” Mrs May said.
"I sincerely regret the fact that I have not yet been able to persuade Parliament."
It was the second time Mrs May has gone to the EU to ask for a Brexit extension.