European Union leaders agreed to grant British Prime Minister Theresa May a new Brexit deadline of October 31, officials said, after French President Emmanuel Macron opposed efforts to give her another year.
"A Brexit extension until 31 October is sensible since it gives time to UK to finally choose its way," Maltese Prime Minister Joseph Muscat tweeted, adding that a summit in June would let EU leaders "take stock of the situation".
Summit chair Donald Tusk he went to brief May on the outcome and seek her necessary agreement to a final deal.
The late-night agreement means Britain will not crash out of the bloc on Friday, and gives May more than the three months she had asked for to build a parliamentary majority behind the withdrawal treaty she negotiated with the EU last year.
But Macron's push for a June Brexit and strong opposition to other leaders' preference for a much longer extension that might increase the chances of Britain changing its mind to stay in the bloc meant the meeting ended up with the October compromise.
October 31 would correspond to the end of the five-year mandate of the present EU executive Commission.
Leaders would meet again in June to assess the situation. Britain could have left by then if May succeeds in building a coalition for her deal with the Labour opposition - though there is no sign of agreement yet.
In order to continue as an EU member beyond June 1, May has agreed to organise British elections to the European Parliament on May 23, though it is still unclear if that vote will go ahead and how far it might turn into a virtual second referendum on EU membership that some hope could mean Britain cancelling Brexit.
The other 27 had all but ruled out pitching Britain, and parts of the EU economy, into chaos on Friday. But a drive by Macron to keep London on a tight leash saw the emergency summit bogged down in late-night wrangling as German Chancellor Angela Merkel and others argued the merits of granting up to a year.
As at a summit last month which put back Brexit for two weeks, several EU diplomats said May failed to persuade her peers that she could definitely break the paralysis of repeated failures to ratify the treaty within the coming months.
- Last-minute Brexit talks ahead of final vote
- Brexit countdown: Four days to deadline
- Million march against Brexit
French officials said the EU faced "blackmail" by hardline pro-Brexit potential successors to May, such as Boris Johnson. They might try to sabotage decision-making, they said.
An aide to Macron warned that France could even be ready to let Britain crash out without a treaty to avoid legal limbo and provide a transition to new trading terms: "Not everything is preferable to a no-deal. A no-deal situation is a real option."
Laughter with Merkel
However, Merkel has urged the bloc to do all it can to avoid such disruption. She said before leaving Berlin that she favoured a delay of "several months" for May, who has pledged to quit if hardcore Brexit supporters in her own Conservative Party drop objections to her "soft Brexit" and help ratify the deal.
Keen to ease tension, Merkel had broken the ice as talks began by showing May a photomontage on a tablet of both wearing similar jackets when addressing their parliaments earlier in the day. It provoked mutual laughter as other leaders joined in.
As talks wore on beyond midnight, with May patiently waiting elsewhere in the building for word on her nation's fate, Macron rallied support for his concerns about a long extension.
May said on arrival that she did not want a long delay: "I want us to be able to leave the European Union in a smooth and orderly way as soon as possible," she told reporters.
Her EU peers, however, are sceptical about her ability to break the deadlock soon and discussed a proposal by Tusk of a "flextension" of up to a year. This, some argued, could increase pressure on May's pro-Brexit critics to back her deal rather than risk Brexit fizzling out.
EU leaders are exasperated with May's handling of a tortuous and costly divorce that is a distraction from ensuring the bloc can hold its own against global economic challenges.
Across from the summit venue, the EU executive celebrated its part in funding a global project that produced the first picture of a black hole, prompting no shortage of ironic comments on social media about the juxtaposition.
Blogger Eliot Higgins tweeted: "We're now more certain about what black holes look like than what Brexit looks like."