The new, Oct. 31 cutoff date averts a precipitous and potentially calamitous Brexit that had been scheduled for Friday.
"Please, do not waste this time," European Council President Donald Tusk pleaded. He said the EU was giving Britain six more months "to find the best possible solution" to its Brexit impasse.
Like many things related to Brexit, the extension was a messy compromise. May came to an emergency summit in Brussels seeking to postpone Britain's departure from the EU until June 30. Some European leaders favored a longer extension, while French President Emmanuel Macron was wary of anything but a very short delay.
Leaders of the 27 remaining EU member states met for more than six hours over a dinner of scallop and cod before settling on the end of October, with the possibility of an earlier Brexit if Britain ratifies a withdrawal agreement.
May said the possibility of leaving before the deadline was a key request of hers.
"I continue to believe we need to leave the EU, with a deal, as soon as possible," she told reporters.
She noted that if U.K. lawmakers back her Brexit deal, Britain could still leave by June 30 — the Brexit deadline she had requested from the bloc — and possibly as soon as May 22, which would release Britain from having to participate in elections for the European Parliament.
May spoke to the 27 EU leaders for just over an hour, before they met for dinner without her to decide Britain's fate. In contrast to some testy recent summits, there were signs of warmth, even humor. May and German Chancellor Angela Merkel were filmed laughing over a tablet bearing an image showing the two of them speaking to their respective Parliaments on Wednesday while wearing similar blue jackets.
While many leaders said they were inclined to grant a Brexit delay, Macron expressed reservations, warning as he arrived at the summit that "nothing is decided."
Afterward, the French president said he was satisfied with the outcome.
"We did the best possible compromise to preserve the unity of the 27 (other EU members) because we have left the United Kingdom more time to deliver a deal," Macron said.
Tusk said that during the extension Britain "will continue its sincere cooperation as a full member state, with all its rights, and as a close friend and trusted ally in the future."
Several months have passed since May and the EU struck a deal laying out the terms of Britain's departure and the outline of future relations. All that was needed was ratification by the British and European Parliaments.
But U.K. lawmakers rejected it — three times. As Britain's departure date of March 29 approached with no resolution in sight, the EU gave Britain until Friday to approve a withdrawal plan, change course and seek a further delay to Brexit, or crash out of the EU with no deal to cushion the shock.
Economists and business leaders have warned that a no-deal Brexit would lead to huge disruptions in trade and travel, with tariffs and customs checks causing gridlock at British ports and possible shortages of goods.
A disorderly Brexit would hurt EU nations, as well as Britain, and all want to avoid it — but there's little agreement about how.
May's future, meanwhile, is uncertain.
She has previously said that "as prime minister" she could not agree to let Britain stay in the EU beyond June 30, and she has also promised to step down once Brexit is delivered. Many Conservative Party lawmakers would like her to quit now and let a new leader take charge of the next stage of Brexit. But they can't force her out until the end of the year, after she survived a no-confidence vote in December.
Every British initiative to get a deal has floundered so far. Several days of talks between May's Conservative government and the main opposition Labour Party aimed at finding a compromise have failed to produce a breakthrough. Labour favors a softer Brexit than the government has proposed, and wants to retain a close economic relationship with the bloc. The two sides said they would resume their discussions Thursday.
Now, the battle begins in Britain over what to do with the extra time.
All options from a no-deal Brexit to a general election to no Brexit at all remain on the table.
Pro-EU politicians said the next few months should be used to hold a new referendum on whether to leave the EU or remain. Labour lawmaker Mary Creagh tweeted that Parliament must move swiftly to break the Brexit deadlock with a confirmatory ballot on PMs deal."
Pro-Brexit lawmakers said it was time to replace May with another Conservative leader — preferably a hard-core Brexiteer.
Irish Prime Minister Leo Varadkar said the time had come for Britain to decide what it wants.
"We're giving them a very long time to take a decision," he said.
"You know, the European Union is not a prison. Nobody has to stay but it is also a home and we are not going to kick anyone out."
As to the symbolic end date? He said it was not on the minds of the EU leaders.
"As I learned this evening, Halloween is not a holiday widely celebrated across the European Union," Varadkar said.
Associated Press writers Mike Corder and Angela Charlton in Brussels, Danica Kirka in London and Sylvie Corbet in Paris contributed to this report.