European leaders agreed with Britain on Thursday to delay Brexit by up to six months, saving the continent from what could have been a chaotic no-deal departure at the end of the week.
The deal struck during late night talks in Brussels means that if London remains in the EU after May 22, British voters will have to take part in European elections.
Prime Minister Theresa May and the other 27 EU leaders "have agreed a flexible extension until 31 October", European Council president Donald Tusk said in a tweet.
"This means additional six months for the UK to find the best possible solution."
France's President Emmanuel Macron was the strongest voice opposing a long extension, but most leaders backed it and the French had to settle for a promise that the delay will be reviewed at an EU summit on June 21.
Most of the leaders gathered for the emergency summit, including German Chancellor Angela Merkel, had backed a plan for Brexit to be postponed for up to a year.
But as the talks went into Thursday morning, Macron -- with backing from Belgium, Austria and some smaller EU states -- held out for a short delay of only a few weeks and demanded solid guarantees that London would not interfere in EU business during that time.
May has already said that if Britain is still an EU member when the European parliamentary election begins on May 23, UK voters will take part. But some EU leaders are unconvinced that she is sincere, despite one official telling reporters her presentation had been "solid".
Without a postponement, Britain would have ended its 46-year membership of the EU at midnight (2200 GMT) on Friday with no deal, risking economic chaos on both sides of the Channel.
May agreed a divorce deal with the EU last November but MPs in London have rejected it three times, forcing her to turn to the main opposition Labour party in a bid to find a way through.
'As soon as possible'
But these talks are moving slowly, and the prime minister is under intense pressure from hardline Brexit supporters in her Conservative party not to compromise.
As she arrived, May said she wanted to leave the EU "as soon as possible".
"I've asked for an extension to June 30 but what is important is that any extension enables us to leave at the point at which we ratify the withdrawal agreement," she said.
She said she still hoped to leave the EU on May 22, the last day before Britain must hold European Parliament elections.
For as long as Britain is in the EU, it must take part in bloc elections for them to be valid.
EU leaders have already agreed one delay to Brexit, from March 29 to April 12, and Tusk has warned there is "little reason to believe" the British parliament can ratify May's deal by June 30.
A draft copy of the summit conclusions seen by AFP before the leaders sat down to finalise it said "an extension should last only as long as necessary and, in any event, no longer than [XX.XX.XXXX]."
"If the withdrawal agreement is ratified by both parties before this date, the withdrawal will take place on the first day of the following month," the draft stated.
EU members want to ensure that a semi-detached Britain does not seek leverage in Brexit talks by intervening in choosing the next head of the European Commission or the next multi-year EU budget.
May's ministers have begun cross-party talks with Labour on a compromise to get the withdrawal agreement through the House of Commons.
Labour leader Jeremy Corbyn wants Britain to commit to remaining within the EU customs union, an idea that many in Europe would be keen to accommodate.
"We would be generous in negotiating that, understanding that the UK couldn't be a silent partner in such an arrangement -- it would have to have a say in decisions being made," Irish premier Leo Varadkar said as he arrived at the summit.