What just happened?

The British government and the European Union (EU) – backed by Ireland – have agreed a deal on the Northern Ireland border, which is the last piece of the puzzle to complete phase one of the Brexit negotiations. The European Commission, the part of the EU which is doing day-to-day negotiations, is happy to move to the next phase of discussions: talks about the transition period and Britain’s future relationship with the EU.

What is the Northern Ireland border problem?

There is currently no hard border between Northern Ireland and the Republic of Ireland – people can walk over the border and not even realise it. Such an arrangement is enshrined in the Good Friday agreement that brought peace to the province.

Everyone says they don’t want a hard border to come back. But Theresa May says Britain must leave the EU customs union and single market as part of Brexit, and the EU says the customs union must have customs checks on its outer frontier.

The solution proposed to this problem was, effectively, to keep Northern Ireland’s regulations in line with the EU’s and give it a special status – basically keeping it in the customs union and single market (because customs union and single markets are basically just a bunch of regulations). This was nearly agreed on Monday.

The problem was that the DUP, a unionist party on Northern Ireland for which Theresa May relies on for her majority in the House of Commons, didn’t like this idea, because it goes against everything they stand for, and vetoed it, deadlocking talks again.

How did they solve the Northern Ireland border issue this time?

A pessimist would say they didn’t really solve the problem – they just kicked the can down the road and said they would come up with a solution later on.

The joint text agreed by the EU and UK doesn’t actually spell out what will happen in Northern Ireland. It says three different things: Firstly, the UK government says it will try and get a UK-wide trade deal with the EU that means there is no need for a hard border in Northern Ireland.

In normal circumstances this would mean staying in the single market and customs union. But Theresa May repeated this morning in Brussels that the UK would be leaving the single market and customs union, so it’s not clear how this would be possible. She could be envisaging a Swiss-style arrangement where the UK isn’t in the EEA, but implements individual tranches of legislation on a treaty basis. This would probably still upset Brexiteers keen on leaving the single market, though. It’s a very odd thing to say and the Government hasn’t unpacked it.

Secondly, the agreement says that if a deal like that isn’t possible, “the United Kingdom will propose specific solutions to address the unique circumstances of the island of Ireland” – which is what they were tried and failed to do, because the DUP blocked the only proposed solution anyone could think of.

Thirdly and crucially, though the agreement pledges “unfettered access” to UK markets for Northern Ireland whatever happens, it places responsibility on the Northern Ireland executive - which doesn’t currently function – to agree any new rules to stop Northern Ireland from diverging from the Republic and thus stop a hard border from forming.

This basically means that if the other points fail, the executive – in which the DUP also has a veto because of powersharing rules – would have to pass the laws to keep Northern Ireland in the single market and customs union, which they say they don’t want.

Who won?

In some ways, this deal means the UK’s negotiators got their way – Britain has always said that it would be easier to solve some of the “separation” issues at the same time as talks about Britain’s future relationship with the EU. Kicking the can down the road is doing just that – seeing if something will turn up.

The EU also got what it wanted in that the integrity of the single market and customs union are still respected in principle.

The DUP also showed that they’re calling the shots in Westminster by humiliating the Prime Minister for a week or so, and they still don’t have to agree to anything they don’t want to agree to.

There is, however, a big danger that the people of Northern Ireland could lose out from the agreement. It’s not impossible that a hard border could emerge in the future – all it takes if the DUP to decide they don’t want to implement a particular regulation at the executive level, and the EU to respond by cutting off access.

Avoiding a border is now reliant on the Northern Ireland executive functioning properly. It currently does not function at all, and hasn’t has a government for months. The issue is far from solved

Did things go down to the wire?

Technically, the UK had until midnight on Sunday evening to come up with a deal, so by recent standards they’ve left it with absolutely ages to spare.

The early start, with Theresa May travelling to Brussels in the small hours of the morning for a press conference at 6.30am London time – was because European Council president Donald Tusk was travelling to Hungary in the morning.

He had already cancelled a trip to Israel on Thursday for a visit from the PM that never came (she was still consulting the DUP), and was apparently determined to make the British work around his timetable.

Brexit bonhomie as May finally seals agreement with EU leaders Show all 10 1 /10 Brexit bonhomie as May finally seals agreement with EU leaders Brexit bonhomie as May finally seals agreement with EU leaders Britain's Prime Minister Theresa May is welcomed by European Commission President Jean-Claude Juncker Reuters Brexit bonhomie as May finally seals agreement with EU leaders EU President Jean-Claude Juncker greeting Theresa May at the EU Commission in Brussels PA Brexit bonhomie as May finally seals agreement with EU leaders Britain's Prime Minister Theresa May poses for a picture with European Council President Donald Tusk REUTERS Brexit bonhomie as May finally seals agreement with EU leaders EU Commission President Jean-Claude Juncker walks behind British Prime Minister Theresa May EPA Brexit bonhomie as May finally seals agreement with EU leaders British Prime Minister Theresa May (L) and European Commission President Jean-Claude Juncker address a press conference at the European Commission in Brussels AFP/Getty Images Brexit bonhomie as May finally seals agreement with EU leaders British Prime Minister Theresa May speaks at a press conference with EU Commission President Jean-Claude Juncker EPA Brexit bonhomie as May finally seals agreement with EU leaders Britain's Secretary of State for Exiting the European Union, David Davis (L) and Michel Barnier (2-L), the European Chief Negotiator of the Task Force for the Preparation and Conduct of the Negotiations with the United Kingdom under Article 50 enter the room by the emergency exit to attend British Prime Minister Theresa May press briefing on Brexit Negotiations in Brussels. EPA Brexit bonhomie as May finally seals agreement with EU leaders Britain's Secretary of State for Exiting the European Union David Davis (L), Britain's Prime Minister Theresa May (2-L), European Commission President Jean-Claude Juncker (2-R) and European Union's chief Brexit negotiator Michel Barnier (R) in a meeting on Friday morning AFP/Getty Images Brexit bonhomie as May finally seals agreement with EU leaders European Union chief Brexit negotiator Michel Barnier speaks during a media conference at EU headquarters Brexit bonhomie as May finally seals agreement with EU leaders European Council President Donald Tusk addresses a media conference at the Europa building in Brussels AP

What happens now?

The Northern Ireland deal is the last piece of the puzzle in phase one of talks. The European Commission now believes “sufficient progress” has been made on the separation issues to move to trade talks.

There’ll be a summit next Thursday and Friday in Brussels where the EU27 will look at the Commission’s recommendations and judge whether they believe sufficient progress has been made. It would be extremely unexpected if they didn’t accept the Commission’s recommendations.

Now the UK and EU have to come up with an agreement on what any transition period could look like. They may also be able to move to talks about Britain’s future relationship past the transition looks like, depending on what the European Council decides next week.