European Union leaders have granted the UK a six-month extension to Brexit, after five hours of talks in Brussels.
The new deadline – 31 October – averts the prospect of the UK having to leave the EU without a deal on Friday, as MPs are still deadlocked over a deal.
European Council president Donald Tusk said his “message to British friends” was “please do not waste this time”.
Theresa May, who had wanted a shorter delay, said the UK would still aim to leave the EU as soon as possible.
The UK must now hold European elections in May, or leave on 1 June without a deal.
Prime Minister Mrs May had earlier told leaders she wanted to move the UK’s exit date from this Friday to 30 June, with the option of leaving earlier if her withdrawal agreement was ratified by Parliament.
Mr Tusk emerged from the talks – and a subsequent meeting with Mrs May – to address reporters at a news conference at 02:15 local time (01:15 BST).
He said: “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.”
Mr Tusk said the UK could also rethink its strategy or choose to “cancel Brexit altogether”.
He added: “Let me finish with a message to our British friends: 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.”
Mrs May was called back into the summit after EU leaders had talked for five hours to find their compromise solution.
Before that, Mrs May had given a one-hour presentation putting forward her argument for the extension date to be 30 June.
This was the second time Mrs May has gone to the EU to ask for a Brexit extension.
So far, MPs have rejected the withdrawal agreement Mrs May reached with other European leaders last year and the House of Commons has also voted against leaving without a deal.
One of most contentious parts of the plan is the Irish backstop – an insurance policy that aims to prevent a hard border returning to the island of Ireland.