London (CNN) The UK and the European Union reached a significant milestone in their pursuit of a Brexit deal on Friday, breaking a deadlock that allows talks to move on to a crucial second phase.

After a dramatic night of shuttle diplomacy that capped months of tortuous negotiations, European Commission President Jean-Claude Juncker and British Prime Minister Theresa May announced the breakthrough at an early morning press conference in Brussels.

Crucially, the two sides reached a deal on the historically sensitive issue of the Irish border, which had threatened to derail the talks as they reached a critical moment earlier this week. Discussions can now move on to the potentially tougher issue of a future trading relationship between the UK and the EU.

The breakthrough represents a significant coup for May, whose beleaguered premiership had appeared under threat as talks faltered. It was also a relief for EU negotiators, who feared a complete breakdown in talks if a deal was not done.

"Getting to this point required give and take on both sides," May said. "And I believe the joint report that is being published is in the best interest of the whole of the UK."

What has been agreed?

Agreement has now been reached on three key issues: Britain's Brexit "divorce" bill, the rights of EU citizens in the UK after Brexit, and the Irish border. When Brexit negotiations began just under six months ago, the EU was clear on its position: It would not countenance any discussion about a future trading relationship with Britain until "sufficient progress" had been made on those three issues.

Irish border: The Irish question proved the toughest to resolve. The demilitarization of the border between Northern Ireland and the Republic of Ireland was a key element of the Good Friday Agreement, the 1998 deal that ended years of sectarian conflict in Northern Ireland. Now, the border posts are gone and people can move freely around the island of Ireland.

But Brexit raised the prospect of a return to a "hard" border, as Northern Ireland would leave the EU while the Republic of Ireland remained in the bloc.

Traffic crosses the border into Northern Ireland from the Irish Republic near Dundalk.

Complicating the issue, May's minority government depends on the support of on a small group of 10 MPs from Northern Ireland, members of the hardline Democratic Unionist Party (DUP). They were adamantly opposed to any suggestion that, to avoid a hard border, Northern Ireland could retain laws and regulations that were more aligned to the EU than the rest of the UK.

The DUP vetoed the text of an earlier deal on Monday, just as May was having lunch with Juncker in Brussels to finalize it. She was forced to return to London as negotiators spent the rest of the week hammering out a solution acceptable to the DUP, the Irish government and the EU.

The language of the deal announced on Friday remains ambiguous. It says: "In the absence of agreed solutions, the UK will maintain full alignment with those rules of the internal market and the customs union which, now or in the future, support North-South cooperation, the all-island economy and the protection of the 1998 agreement."

That's a backstop. It means that, in the next stage of talks, the UK must come up with solutions that avoid a hard border, otherwise the UK will have to remain tied to EU rules even after Brexit. That scenario would enrage the ardent Brexiteers in May's Conservative Party.

Divorce bill: Friday's agreement says the UK would be required to continue making contributions to the EU budget up to the end of 2020 "as if it had remained in the union". The report adds that the UK will remain liable for its outstanding financial commitments and liabilities up to December 3, 2020.

A spokesman for the UK government put the estimated net cost of the divorce bill at between £35 billion and £39 billion ($47 billion and $52 billion) adding that this estimation "represents a fair settlement of our obligations."

Rights of EU citizens after Brexit: EU citizens living in the UK and vice versa will have their rights to live, work and study protected. British courts will enforce the rights but, in a concession to Europe, the UK has agreed that difficult cases can be referred to the European Court of Justice for eight years after Brexit.

Late-night drama

Discussions stretched into the early hours of Monday morning. When it was clear that a deal was done, May and her chief Brexit negotiator David Davis dashed to Brussels for a breakfast meeting with Juncker and other officials.

Speaking alongside Juncker in the Belgian capital, May said the agreement was "fair to the British taxpayer" and resolved the outstanding issues of the Irish border. In Northern Ireland we will guarantee there will be no hard border, and we will uphold the (Good Friday Agreement)."

"No barrier north-south or east-west," she said.

Juncker said: "Sufficient progress has now been made on the three terms of the divorce." Negotiations for the UK to leave the EU can now proceed to the next stage, he added.

If agreement had not been reached on Friday it would have been impossible to prepare for its ratification at a summit of EU leaders on December 14 and 15, he said. "We had to make the deal today."

Reaction

The leader of the DUP, Arlene Foster, claimed she had secured "substantial changes" to the text she rejected on Monday, adding she was "pleased" to see changes which mean there is "no red line down the Irish Sea".

In a statement, the DUP said it had won clear that commitments from the Conservatives that "Northern Ireland will leave the single market and the customs union along with the rest of the United Kingdom."

JUST WATCHED Brexit showdown bringing uncertainty to UK Replay More Videos ... MUST WATCH Brexit showdown bringing uncertainty to UK 01:48

Ireland's Prime Minister Leo Varadkar said that the UK had guaranteed there would be no hard border and that the 1998 Good Friday Agreement had been fully protected. "It's a very significant day for the island of Ireland," he said.

Varadkar added that the common travel area, the arrangement that allows citizens to travel freely between Britain and Ireland, would remain in place and that Irish and British citizens would continue to enjoy the same rights after Brexit as they do now.

In London, the reaction from May's colleagues was mostly positive. UK environment secretary Michael Gove, one of the leading figures in the Leave camp during the Brexit referendum, said: "I think it's important to recognize this is a significant personal political achievement for the Prime Minister."

"She got a deal in the interests of the whole of the UK, so the integrity of the UK is absolute and paramount," he told BBC Radio 4's Today program.

But former UKIP leader Nigel Farage, who has long championed Brexit, criticized May over the deal, claiming the country could now "move on to the next stage of humiliation."

Donald Tusk, President of the European Council, warned that the next stage of negotiations would be even tougher. ''Breaking up is hard, but breaking up and building new relations is much harder," he said.