The UK is heading for a Halloween Brexit after the remaining 27 EU nations offered Theresa May a further six months to ratify or rethink her withdrawal deal.

The second extension to the Brexit process - initially intended to conclude on March 29 - definitively stopped the clock on a no-deal withdrawal on Friday with less than 48 hours to go.

In an early-hours press conference, European Council president Donald Tusk did not rule out further extensions beyond October.

And he sent a message to the UK: "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."

First Minister Nicola Sturgeon said it was a "relief" that the UK would not be leaving the EU on Friday, adding that "allowing people to decide if they still want to leave is now imperative".

Addressing the press shortly before 2am, May said that she still wanted the UK to leave the EU "as soon as possible".

If a withdrawal deal could be ratified within the first three weeks of May, the UK could still avoid participation in that month's European Parliament elections and leave the EU in June, she said.

Acknowledging "huge frustration" among voters that the UK has not yet left the EU, she said: "The choices we now face are stark and the timetable is clear.

"So we must now press on at pace with our efforts to reach a consensus on a deal that is in the national interest."

Talks between the government and Labour to find a compromise way forward will continue at official level on Thursday.

"I do not pretend the next few weeks will be easy or that there is a simple way to break the deadlock in Parliament," said Mrs May.

"But we have a duty as politicians to find a way to fulfil the democratic decision of the referendum, deliver Brexit and move our country forward. Nothing is more pressing or more vital."

The six-month extension was a compromise solution thrashed out in five hours of talks in Mrs May's absence, after French President Emmanuel Macron held out against a longer extension lasting into 2020.

Under the terms of the agreement, the UK can leave at any time if the Withdrawal Agreement reached last November is ratified by the Westminster Parliament.

If the UK fails to take part in elections to the European Parliament on May 23-26, it will automatically leave without a deal on June 1.

A review of progress will take place at the scheduled June 20 European Council summit in Brussels, but Mr Tusk stressed that this would be an opportunity for "taking stock" and not for any new negotiations.

The term of the current European Commission under Jean-Claude Juncker ends on October 31.

A UK exit by that date would get round the diplomatically awkward requirement for London to appoint a new Commissioner to his successor's team.

But asked whether a further extension might be possible, Mr Tusk replied: "Our intention is to finalise the whole process in October... but I am too old to exclude another scenario. I think still everything is possible."

Mrs May gave a one-hour presentation setting out her case for an extension to June 30, with a break clause allowing the UK to leave as soon as her Withdrawal Agreement was ratified.

But she had to leave the EU27 to discuss the UK's future in her absence over a dinner of scallop soup and loin of cod.

It took five hours of wrangling before she was summoned back from the residence of UK ambassador Sir Tim Barrow at almost 1am Brussels time (12am BST) for her agreement to be sought.

She consulted Attorney General Geoffrey Cox by telephone before confirming that the new deal was acceptable.

The extension to the autumn will fuel demands from angry Tory backbenchers for Mrs May to resign and hand over to a new leader.

But senior British sources indicated that the PM intended to stand by her promise to the party's backbench 1922 Committee to stand down once the first phase of Brexit negotiations are complete.

A Halloween Brexit would mean the second phase - dealing with the future UK/EU trade and security relationship - would not get under way until late in the autumn.