The EU and the UK announced dramatically on Thursday that agreement had been reached on a Brexit deal to take the United Kingdom out of the European Union.
European Commission President Jean-Claude Juncker and British Prime Minister Boris Johnson both tweeted almost simultaneously to say that a deal had been struck.
However, Johnson faces resistance in getting any deal through the UK parliament. His allies in Northern Ireland's unionist party the DUP said on Thursday that they rejected the proposed accord "as things stand".
For the latest developments, follow our updates here.
The announcements came as a key summit of EU leaders was due to get underway in Brussels. Until now an agreement on a revised Brexit deal had proved elusive -- with two weeks to go until the UK's scheduled departure from the EU.
Boris Johnson -- who will attend Thursday's EU meeting -- has been struggling to win over crucial allies at home. In what looks like a major blow for the UK prime minister, Northern Ireland's Democratic Unionist Party (DUP) released a statement on Thursday morning saying it could not support the latest proposals "as things stand".
The support of the DUP and Conservative Eurosceptics are seen as crucial if any deal is to be passed by the UK parliament, where Johnson's government has no majority.
"As things stand, we could not support what is being suggested on customs and consent issues and there is a lack of clarity on VAT," the DUP statement says.
"We will continue to work with the government to try and get a sensible deal that works for Northern Ireland and protects the economic and constitutional integrity of the United Kingdom."
Earlier, the European Commission said its president Jean-Claude Juncker spoke to Boris Johnson on Thursday morning. “Every hour and minute counts before the (EU summit). We want a deal,” Mina Andreeva tweeted.
No further movement had materialised on Wednesday evening after another day of technical talks between UK and EU negotiators.
A spokesman for the British prime minister said earlier that he had told his cabinet that while talks hadn't finished, he believed there was a chance of securing "a good deal".
Any approval by the EU for a deal at their summit would be conditional on the House of Commons backing it at a special sitting on Saturday. The UK is due to leave the EU on October 31 but a short delay is seen as inevitable, given the challenge of drawing up a legal text and getting it ratified.
Cautious optimism before the summit
European Council President Donald Tusk told Polish media earlier on Wednesday that an agreement on Brexit could be made by Thursday morning.
"The most important part of the deal is ready," he said to TVN 24 on Wednesday afternoon.
"And, theoretically, we could accept this deal tomorrow and avoid the chaos and misfortune that would be associated with an uncontrolled exit of the UK."
But Tusk noted that "everything is still possible" in the coming hours as there is still "a mess" on the British side.
The French and German leaders were optimistic as they met in Toulouse on Wednesday.
"I want to believe an agreement is being finalised and that we will be able to endorse it tomorrow," French President Emmanuel Macron said at a joint news conference with Angela Merkel. The German Chancellor said she believed that a deal was possible.
However, Merkel told the German Parliament on Thursday that point had still not been reached.
The German Chancellor added that the EU would “not allow hate and violence to return to the Irish island caused by a hard border”, and that the Good Friday Agreement and the EU’s single market had to be protected. “I can’t stress this enough,” Merkel said.
What is in the new deal?
Reports have suggested the UK has made concessions in response to the EU's concerns over the Irish border and customs arrangements. Boris Johnson wants to ditch the backstop measure in the original withdrawal agreement, which as an insurance policy to keep an open frontier would keep the UK in a customs union with the EU.
Although the British government wants Northern Ireland to leave the EU's customs union along with the rest of the UK, the prime minister is said to have agreed that different rules will apply to the North under a dual customs regime.
EU officials said on Wednesday that agreement had been reached on customs arrangements for Northern Ireland, "level playing field" provisions on labour and environmental standards. The EU has insisted on these to ensure fair competition under a new trade deal after Brexit.
Agreement is also said to be there on the issue of consent by Northern Ireland for new border plans. Reports say the Northern Ireland Assembly would be able to vote on the new arrangements four years after the end of a post-Brexit transition period.
EU sources said VAT (Value Added Tax) was the only outstanding element between the UK and the EU, Reuters reported.
Much depends on the stance of Conservative Eurosceptics from the European Research Group (ERG) and Northern Ireland's Democratic Unionist Party (DUP), whose lawmakers the UK prime minister has been trying to convince. The parliamentary arithmetic is highly uncertain, however, and the government will also be looking for support from others on the backbenches.
Saturday (October 19) is the date when under the terms of the Benn Act the prime minister will be obliged to seek another Brexit delay from the EU if a new deal has not been approved by parliament.
Earlier this week, the EU's chief negotiator Michel Barnier said a deal would be "very, very difficult but possible". Before Tuesday's meeting of EU ministers, he said it was time London "turned good intentions into a legal text."
Boris Johnson had previously said he wanted to reach a Brexit deal at an EU summit on Thursday and Friday to allow for an orderly departure on October 31.
The main problem remains the border between Ireland and Northern Ireland and how to prevent it becoming a backdoor into the EU after Brexit.
A border on the island could undermine the 1998 peace agreement that helped end three decades of sectarian violence.
There is said to be frustration in Brussels that a deal could be threatened by the domestic political situation in the UK -- as happened with Johnson's predecessor Theresa May when her government was negotiating with the EU.