Theresa May came closer than ever on Monday to the Brexit deal she’s been working on for months. A last-minute upset over the Irish border left all parties embarrassed and doesn’t bode well for a second run at a breakthrough.

Irish Prime Minister Leo Varadkar said a solution to an intractable problem — what to do with the shared border with Northern Ireland when the U.K. leaves — had been agreed in the morning and unraveled while May was at a lunch with European Commission President Jean-Claude Juncker in Brussels.

The meal that should have been the clincher was interrupted by a phone call between May and Arlene Foster — the leader of the Democratic Unionist Party, which opposes the EU’s plans for the island after Brexit and props up May’s government in London. For the DUP, any proposal that would apply to Northern Ireland and not the rest of the U.K. was going to be a problem.

Shortly afterwards Juncker emerged to deliver a two-minute statement saying “it was not possible to reach a complete agreement today.” The divisions over Ireland and the powers of the European Court of Justice had proven too great.

The episode will make striking a deal by the end of the year harder, according to a person familiar with the Irish government’s thinking. Dublin had signed up to the agreement and was happy with it and any change now to placate May’s Northern Irish allies will look like a concession from Dublin.

Surprised, Disappointed

“I am surprised and disappointed that the British government now appears not to be in a position to conclude what was agreed earlier today,” Varadkar told reporters in Dublin. He raised the possibility of another summit in January if December is a flop.

Both sides vowed to carry on talking this week. Juncker was generous to the embattled prime minister and said he is confident that getting a result in time for a summit in mid-December is still within reach.

That deadline looms large because it’s only once leaders conclude Britain has achieved “sufficient progress” in the first phase of talks that trade negotiations can start and the transition arrangements wanted by businesses can be put in place. It’s 17 months since the referendum and Britain will leave the bloc in 15 months, with or without a deal.

Court of Justice

But it’s not just the Irish border standing in the way of a deal, according to another person familiar with the situation. The reach of the European Court of Justice in the U.K. after Brexit was also a stumbling block.

It’s an issue of totemic importance to both sides, with some members of May’s Conservative party seeing it as a symbol of lost sovereignty while the veto-wielding European Parliament says it must have a role in protecting EU citizens.

The U.K. had downplayed expectations going into the lunch meeting on Monday, saying it was a staging post on the way to the council summit on Dec. 14 and 15. But as May traveled to the appointment, hopes were raised when chief EU negotiator Michel Barnier told a group of European lawmakers that a breakthrough was imminent.

They then told the world, even as U.K. officials continued to call for caution. The pound rose on their comments, only to fall later when reality sunk in.

The Irish border was always going to be the kind of challenge that would require a lot of political will on all sides. The current invisible border is possible because both Northern Ireland, which is part of the U.K., and the Republic of Ireland are members of the EU’s single market and customs union.

When the U.K. leaves the EU, Northern Ireland goes with it.

May has just days to do what she has failed to do in months: find a formula on the Irish border that’s acceptable to both parties and find a concession she can offer on the ECJ that won’t enrage elements of her party so much they decide they’ve had enough.

The stakes are high: May’s own position as prime minister is precarious as senior members in her Tory party want to replace her after she led them in a failed election campaign. The June vote cost May’s Conservatives their majority and left them relying on the DUP to get legislation through Parliament.

The debate over Northern Ireland also threatens to generate more tension in the already fractious union. As details leaked of the proposed exception for Northern Ireland, remain-voting Scotland and London piped up to ask for the same.

“We’ve been negotiating hard and a lot of progress has been made and on many of the issues there is a common understanding,” May said before heading back to London. “On a couple of issues some differences do remain which require further negotiation and consultation.”