EU leaders have moved the Brexit cliff-edge back until 12 April in a move that gives an embattled Theresa May one last opportunity to secure MPs' backing for her deal at a third attempt or change course, which could mean general elections or a second referendum.
Theresa May will have a two weeks' grace period to devise an alternative Brexit plan if her deal falls next week after the prime minister failed to convince the bloc that she was capable of avoiding a no-deal Brexit.
Under the deal agreed by May, Britain will now stay a member state until 12 April if the withdrawal agreement is rejected by MPs at the third time of asking.
This is perhaps the last chance for Britain to say what it wants for the future"
The government will be able to seek a longer extension during that period if it can both "indicate a way forward" and agree to hold European elections.
The UK prime minister said: "What the decision today underlines is the importance of the House of Commons passing a Brexit deal next week so that we can bring an end to the uncertainty and leave in a smooth and orderly manner."
Although May said she believed "it would be wrong" for Britain to take part in elections to the Strasbourg parliament in May, she did not exclude it as a possibility. However Downing Street said a no-deal exit was "still on the table".
"The 12 April is the new 29 March," an EU official said.
Donald Tusk, the European council president, told reporters in a late-night press conference that he had several meetings through the evening to secure May's agreement.
He said: "What this means in practice is that, until that date, all options will remain open, and the cliff-edge date will be delayed. The UK government will still have a choice of a deal, no-deal, a long extension or revoking article 50."
Asked how long an extension could be on offer, the European commission president, Jean-Claude Juncker, said: "Until the very end."
A long extension is envisaged as being for one year, giving time for Britain to hold an election, a referendum or both. This avoids delaying so long that Britain's presence would complicate negotiations for a new EU long-term budget from 2021.
Preparations for a no-deal, in which Britain would face sudden trade barriers and restrictions on business, were still underway, however, Belgium's prime minister told reporters.
"This is perhaps the last chance for Britain to say what it wants for the future," Charles Michelsaid. "More than ever, this is in the hands of the British parliament," he said, adding that the 27 EU leaders were not blind to the risks of a no-deal.
Luxembourg's Prime Minister Xavier Bettel said he believed May, who did not attend the second day of the summit, had a 50:50 chance of getting the deal through the House of Commons.