There are two places where agreements rarely happen on schedule – Brussels and Belfast. So, expecting a deal that involved both Brussels and Belfast to close on time called for more than the usual level of optimism.

Yes, it would have been nice for (almost) all concerned if everything had been wrapped up as planned today. But that would not have been the end of it. Particularly for the British Prime Minister.

It is in the nature of political deals that not everybody can get everything they want. For Theresa May, this problem is particularly acute. The "deal" done in Brussels was not going to go down well with Northern Ireland unionists, nor with hardline Brexiters in the Tory party: it does give special treatment to Northern Ireland, and it does limit the UK’s room for manoeuvre in trade negotiations when it leaves the EU.

But it’s not all a one-way street. The "deal" was very carefully crafted.The Irish Government gave ground in helping to get it over the line: from no regulatory divergence between north and south, it moved to acceptance of regulatory alignment on the island of Ireland, in the absence of any other deal.

No divergence is very stringent: regulatory alignment leaves plenty of room for ambiguity, fudge and creative interpretation. This considerably sweetened the deal for the British side, suggesting as it does that instead of the UK parliament having to cut and paste rules from Brussels, it will instead be able to make its own rules, as long as the outcome of those rules is broadly the same as the EU rules (which suggests a fairly cosy future relationship between British Civil Servants and the EU).

The Regulatory Alignment would only apply in Northern Ireland, and only in those areas that underpin the Good Friday Agreement.

It might have been enough to get past the Conservative Party, if the lure of getting into phase two discussions – especially on trade – were enough to persuade them to swallow the unpalatable restrictions this deal places on the hardline Brexiter vision of the UK’s future.

Here is what Belgian Green MEP Philippe Lamberts, a member of the Brexit steering group of the European Parliament (and well briefed on the talks process) said this afternoon before the deal went wrong:

"It seems the British government is now coming to terms with reality and is finally willing to make the necessary concessions to allow us to move on to stage two of the negotiations. While the hard-line Brexiteers will not be happy, the necessity of a special agreement for Northern Ireland has been clear to all rational observers since day one. Maintaining regulatory alignment between Northern Ireland and the Republic of Ireland is the only solution if the Good Friday Agreement is to be respected. I am optimistic that the European Council can now agree to move discussion on to the UK’s future relationship with the European Union."

Perhaps – as ITV’s Robert Peston has suggested – it might be enough for the pro-remain majority in the House of Commons to back the deal, even if the DUP and the hardest of the hardcore Brexiters defected.

Perhaps Mrs May had decided it is time to face down the opposition from within and deliver a Brexit that can be delivered without risking economic dislocation and political strife with the European neighbours.

Either way, today’s "deal" involved a gamble by Mrs May – a bet that with enough of a push she could push the deal through and get to the trade talks nirvana of phase two, while the Christmas holidays helped to take the wind out of opposition attempts to whip up public outrage and undermine her authority.

But it seems it was the DUP – and the ten votes that give Mrs May her parliamentary majority – that scuppered the deal today. Or maybe they have just delayed it.Maybe, in the time honoured way of Brussels, if something isn’t ready, it’s just not ready and more time is needed to work a side deal with one government or another.

But this problem is not a classic Brussels problem – it’s a new United Kingdom problem. New, because it potentially further destabilises the UK’s constitutional arrangements.And not just in Northern Ireland. Look at what the First Minsters of Scotland and Wales, and the Mayor of London said about the "deal".

"While I welcome the proposed commitment for Ireland and Northern Ireland – and while the particular circumstances in Scotland are distinct and separate from those in Ireland – today’s developments show very clearly that if one part of UK can retain regulatory alignment with the EU and effectively stay in the single market, there is no good practical reason why others cannot do the same … Scotland voted overwhelmingly to remain in the EU, and the Scottish Government will continue to make the case, as strongly as ever, for that democratic choice by the people of Scotland to be respected and for our place in Europe to be protected." - Nicola Sturgeon, First Minster Scotland.

"We cannot allow different parts of the UK to be more favourably treated than others. If one part of the UK is granted continued participation in the Single Market & Customs Union, then we fully expect to be made the same offer." - Carwyn Jones, First Minister of Wales.

"Huge ramifications for London if Theresa May has conceded that it's possible for part of the UK to remain within the single market & customs union after Brexit. Londoners overwhelmingly voted to remain in the EU and a similar deal here could protect tens of thousands of jobs. "The clear solution to this government chaos is a deal that protects both the Good Friday Agreement and our national economy after Brexit - UK remaining in the single market and customs union." - Sadiq Khan, Mayor of London

The DUP is the largest party in Northern Ireland, but, as Taoiseach Leo Varadkar pointed out in his press conference this evening, not in government in Northern Ireland, and not the party of the majority in Northern Ireland.

Nevertheless they have come out swinging. Here is Sammy Wilson on BBC Radio Ulster earlier today:

"The British government couldn’t even make that kind of commitment because of course it would be assuming that we would be prepared to abide by an arrangement such as that. We have made it quite clear that we will do nothing which separates us from our main market which is the United Kingdom. How could we even deliver on such a promise? That is why I suspect that the kind of information … they are working on is probably not correct." "We have argued our case vigorously with the government, we have won that case, we have got the political leverage in the House of Commons to hold the government to the agreement that they will in no way separate economies or territorial integrity of the U.K., and we will do that."

And then there was the official statement by party leader Arlene Foster:

"We will not accept any form of regulatory divergence which separates Northern Ireland economically or politically from the rest of the UK.The economic and constitutional integrity of the UK will not be compromised in any way. Her Majesty’s government understands the DUP position. The Prime Minister has told the House of Commons that there will be no border in the Irish Sea. The Prime Minister has been clear that the UK is leaving the European Union as a whole and the territorial and economic integrity of the UK will be protected. We want to see a sensible Brexit where the Common Travel Area is continued, we meet our financial obligations, have a strictly time limited implementation period and where the contribution of EU migrants to our economy is recognised in a practical manner.""

Arlene Foster: NI must leave the EU on the same terms as the rest of the UK pic.twitter.com/u36Iwzb4Vg — RTÉ News (@rtenews) December 4, 2017

But there is a possible way out in this statement. The DUP don’t want any regulatory divergence with the rest of the UK. And nor does the Mayor of London.

His call – for the UK to remain in regulatory alignment with the EU - would probably get around the issue of both NI not having a separate regime from the rest of the UK, and the UK not having to have a hard border at either Dundalk or Dover.

On his visit to Dublin last month British Foreign Secretary Boris Johnson was criticised for saying the solution to the Northern Ireland border would be the same for the Border at Dover.Maybe he was on to something.

And there was Mrs May’s earlier call for a new customs agreement between the UK and the EU customs union. Could it be the one in which there is regulatory alignment that would allow the UK to trade in goods in virtually the same way it does today? That is, without hard borders.

This sounds like the kind of political deal the Irish Government have been after – a top level decision from which flows most of the other elements of the future relationship between the UK and the EU. Some commentators in the UK have even given this political direction a name: soft Brexit.

But to get to this point, probably the position most acceptable to the majority of MPs in Westminster, a vulnerable Prime Minister has to get it past the hardline Euro sceptics (in both the Conservative and Labour parties) and their friends in the British media, and the DUP, and the devolved administrations in Scotland and Wales (who feel profoundly ignored in this process).

Ian Dunt of Politics.co.uk has a very pessimistic view of her trilemma:

"May has three choices, all of which break her. If she insists on a border in Ireland, the talks break down and she is finished. If she insists on a border in the Irish Sea, the DUP pull the plug on her parliamentary deal and she is finished. If she accepts regulatory alignment for the whole of the UK, the Cabinet hawks revolt and she is finished. Whatever happens, it's hard to see how she survives."

Stand by for an enormous fight in Westminster. It’s been coming for well over a year. The Brexit process cannot make much headway without having it. It’s going to be ugly. You have been warned.