There wasn’t even a Brexit deal yet when the Democratic Unionist party announced it could not support it. “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 party said in a dawn statement.

Customs, consent and VAT: three technical issues that have weighty implications for Brexit and the UK’s political future. Customs and consent had been the two big stumbling blocks since serious talks on Boris Johnson’s renegotiation of the Brexit deal began this month. The tricky VAT problem wasn’t yet settled when the DUP put its cards on the table, raising the possibility of the EU’s worst nightmare – a fourth rejection in the Commons of the withdrawal agreement.

With five hours left until EU leaders were due to arrive for their summit, some of Brussels’ most senior officials did not have a clue what would happen. “Maybe we will have a deal or maybe not,” one official said. “We somehow got used to this, we know that when Brexit is on the agenda we should expect the unexpected.”

After months of grandstanding on both sides, the wheels were turning. British and EU officials had worked into the small hours of Thursday morning to iron out their differences on VAT. The British had mostly caved in to EU demands that Northern Ireland should follow EU rules. With Brexit hanging in the balance, one of the last difficulties was a VAT derogation for sanitary products – an echo of an earlier battle between David Cameron and Brussels.

At 9.30am Johnson had a “friendly” 20-minute phone call with Jean-Claude Juncker to discuss the results of the previous night. The prime minister thanked Juncker several times for his patience. At 11am the two men spoke again: they had a deal.

Less than 30 minutes after putting the phones down, the announcement was made via two coordinated tweets that rallied the pound for a short while. “It is high time to complete the withdrawal process,” Juncker said as he urged EU leaders to back the deal that day.

Johnson turned to the slogan of the 2016 leave campaign: “We’ve got a great new deal that takes back control – now parliament should get it done on Saturday so we can move on to other priorities,” the prime minister tweeted.

In reality much of Theresa May’s deal remains, notably protection of the rights of 5 million citizens of the EU and UK affected by Brexit, the divorce settlement and a transition period. The rewritten Irish protocol is modelled on the EU’s original plan for Northern Ireland, a proposal rejected by May 18 months ago, but the EU has given ground on consent.

While Johnson sounded bullish, EU leaders did not hide their regret. Donald Tusk, the anglophile president of the European council, said he felt sadness. “Because in my heart I will always be a remainer. And I hope that if our British friends will decide to return one day, our door will always be open.”

Juncker said it was “high time” to complete Brexit but also sounded a wistful note. “The good news is we have a deal … the bad news is that Britain will leave the European Union.”

He also managed to rile British remainers by saying he had ruled out any extension of article 50 – in reality a promise the outgoing commission president cannot make.

The atmosphere in Westminster was febrile as attention turned to the 28 hardline Eurosceptics and about 20 pro-deal opposition MPs who might have their arms twisted into voting for Johnson’s agreement. The Labour would-be rebels were largely silent, telling reporters they were “on lockdown” and “needed some time to think” about the enormity of the decision in front of them.

One texted to ask: “Is it true that Juncker’s statement means no more extensions?” In conversations between them, they discussed whether they needed more time and reassurances on the legal text, possibly forcing Johnson into a short extension.

Eurosceptics also said they needed time to examine any legal text of an agreement. And there were rumblings of discontent extending wider than the original 28 so-called Spartans of the ERG who voted down the last agreement.

Iain Duncan Smith, the former Tory leader who ended up voting for May’s deal, said he had reservations. As he prepared for an interview with ITV, the prime minister’s personal number flashed up on his phone screen. And one Eurosceptic was overheard by the Huffington Post’s Paul Waugh shouting: “If you try and co-opt me, I’ll fuck over the government, the prime minister, don’t push me.”

But a trickle of hardliners began to indicate they were likely to back the deal, including Andrea Jenkyns, Andrew Bridgen and Ranil Jayawardena. The most fervent Brexiter of them all, Steve Baker, continued to make positive noises. In a joint statement with Mark Francois, he said: “*If* we vote for this agreement, after dealing with limited remaining concerns, we will also see through the implementing legislation to completion. Provided it is not adversely amended.”

With the long-awaited Brexit legal text released just hours before the EU’s “final” deadline, EU leaders welcomed the prospect of a deal. Luxembourg’s prime minister, Xavier Bettel, who recently voiced his anger at Johnson’s no-show at a press conference, said he was positive.

Making his EU summit debut, Johnson toured the room shaking hands with fellow leaders during the on-camera mingling before the doors close. Smiling, a little play-acting, the prime minister performed a mock bow to one guest and got a friendly tap on the cheek from the Cypriot president, Nicos Anastasiades. He shared a joke with Bettel, who laughed uproariously, slapping him on the back. It was a very different image to that of his predecessor, who was caught looking awkward at her first summit.

After the pleasantries Johnson spent just 25 minutes talking to EU leaders, where he assured them he could get the deal through parliament. He used some of his brief time in the summit chamber to reminisce about his school years in Brussels, telling leaders of his life-long understanding of Europe. He said the UK had never been truly European, but always half in, half out.

Beyond the bonhomie and backslapping, EU leaders fear Johnson’s Brexit deal could meet the same fate as May’s. The EU chief negotiator, Michel Barnier, told journalists that Johnson had reassured the commission he was confident the deal could pass.

EU leaders have heard this talk before. The French president, Emmanuel Macron, said he “want[ed] to believe” that Johnson would get a majority. One EU ambassador told counterparts they had an uneasy feeling about being at the mercy of the House of Commons for a fourth time.

Brussels is nonplussed by British assurances, having heard estimated ratification times dwindle from six months to so many days. “We were told in 2018 by the UK government that the ratification takes six months,” the senior EU official observed. “In the beginning of 2019 we were told it takes six weeks and the latest is that a few days is more than enough. So we will see.”

Johnson’s first EU summit is meant to be his last. But nobody on the EU side is ruling out anything, despite Juncker’s public comments – politically useful for No 10 – about ruling out an extension. The EU president acknowledged the reality: “I am not in charge of Westminster.”