Boris Johnson agreed in the final hours of the Northern Ireland Protocol negotiations that there would be customs declarations on goods exiting Northern Ireland to Britain, despite the fact that just three weeks later he told businesses in the North there would be "no forms, no checks, no barriers of any kind…," according to a detailed new account of the protocol negotiations.

The former British prime minister also told Taoiseach Leo Varadkar in the days leading up to the deal in October 2019 that the protocol would not just maintain the all-Ireland economy but "deepen" it.

Mr Johnson also explicitly accepted a role for the European Court of Justice in the surveillance and enforcement of EU single market rules for goods in Northern Ireland once the protocol took effect.

The revelations are contained in a new book by a senior EU official present throughout the five years of negotiations between the EU and UK, as Britain formally left the European Union and forged a new relationship.

'Inside the Deal: How the EU got Brexit' done, by Stefaan De Rynck, a close aide to the EU’s chief negotiator Michel Barnier, will be published shortly.

It details the trauma of the Brexit process from an EU perspective, from the referendum in June 2016 to the prolonged parliamentary chaos of the Withdrawal Agreement and through to the conclusion of the Trade and Cooperation Agreement.

Much of the book focuses on the agonising negotiations on how to reconcile the British government’s insistence that there would be no hard border on the island of Ireland as a result of Brexit, despite the UK exiting the EU’s single market and customs union.

Mr De Rynck contends that the EU protecting Ireland’s interests throughout was not pre-determined in the immediate aftermath of the shock exit vote.

The first suggestion of Northern Ireland somehow staying in the EU's single market as a way to avoid a hard border came from an Irish diplomat, who said Brussels should look at the experience of west Germany, which since 1957 had not imposed EEC customs and regulatory checks on east German goods because Bonn had not recognised east Germany as a separate country.

"It was an off-the-cuff remark and no-one on the EU side paid it much attention. The idea of treating Northern Ireland as if it were part of the EU for trade in goods had not crossed people’s minds yet," writes Mr De Rynck.

It was not until December 2016, six months after the Brexit referendum, that the then European Commission president Jean-Claude Juncker would give then taoiseach Enda Kenny a one-page note committing that the EU would take care of all Irish issues.

However, in early 2017 the EU and Ireland were still exploring how to keep the land border soft through technology, with Mr Barnier asking Mr Kenny to look at an all-island zone with the same health rules for food and animal feed.

Michel Barnier and Enda Kenny pictured in the taoiseach's office in 2017

The commission warned, however, that infrastructure at the land border would be unavoidable.

"On customs, no matter how much use there might be of x-rays to scan trucks or cameras and technology for licence plate recognition of vehicles crossing the border there would always be a need for physical infrastructure and equipment," Mr De Rynck writes.

The memoir also refutes the notion, promoted by unionists and Brexiteers, that it was Leo Varadkar who hardened Ireland’s position when he became Taoiseach in March 2017 by ending talk of a hi-tech solution to the border.

"Kenny decided it was time to freeze the technical work and give more time first to political leadership. It was not the case as has been suggested that an inexperienced Varadkar changed course from the more 'pragmatic Kenny.’"

Mr De Rynck recalls Mr Kenny pulling Mr Barnier aside into a small photocopy room in the European Commission headquarters in Brussels in early 2017. "He told him there was no reason to put pressure on the EU. Why should Ireland have to solve the technical problems created by the political choice of Brexit?"

The embryo of the Northern Ireland Protocol first appeared in paper form in November 2017, following the so-called "mapping exercise" carried out by EU, Irish and UK officials in 2017 to determine the extent to which North-South cooperation under the Good Friday Agreement (GFA) depended upon, or was enhanced by, shared EU membership.

The working paper circulated by the European Commission to member states included the proposal that, in order to protect North-South cooperation and the all-island economy, there should be "no regulatory divergence" from EU single market rules in Northern Ireland, if other solutions could not be found.

Despite the UK's anger at the suggestion, "Irish diplomats…encouraged the UK to solicit DUP support and convince unionists that Northern Irish farming could thrive better by staying in the EU single market for goods."

In December 2017, the UK signed up to the so-called Joint Report, accepting the notion of Northern Ireland remaining in the single market for goods as a "backstop", if two other solutions - the future trade relationship and the so-called "alternative arrangements" of technology - did not ensure the absence of a hard land border.

When the European Commission, under instruction from EU leaders, converted the report into a legal text the following February (2018), the then prime minister Theresa May attempted unsuccessfully to prevent the commission from publishing the text, according to Mr De Rynck.

When the text was published, Mrs May told the House of Commons that "no British prime minister" could ever accept a customs border in the Irish Sea.

Former British prime minister Theresa May

Mr De Rynck writes that the statement "...frustrated Barnier’s team that its backstop was declared politically dead in the water in London whereas May’s negotiators continued to work on it in Brussels and affirmed that the UK would make sure Ireland could fulfil all EU obligations of the single market and customs union."

The book depicts the agony of Mrs May as she pushed for a UK wide customs union with the EU as a way to avoid an Irish Sea customs border, suffering the resignations of Boris Johnson, David Davis (her Brexit Secretary) and Steve Baker.

She ultimately failed to get the 2018 Withdrawal Agreement, which contained the backstop, through the House of Commons on two separate occasions.

Following Boris Johnson’s ascent to Downing Street in July 2019, Mr De Rynck describes how his promise to "bin the backstop" was gradually eroded in the autumn of 2019.

At one point Mr Johnson proposed a "two borders, four years" approach. This envisaged an all-island agrifood and animal health regime under EU rules but with checks on goods moving across the land border being carried out at customs processing centres dispersed throughout Ireland.

The "four years" referred to the Northern Ireland Assembly having a vote on the arrangements every four years, with the assembly being able to reject the backstop coming into effect, even if it was approved by the House of Commons.

By October 2019, shortly before the famous meeting with Leo Varadkar in Liverpool, the UK had agreed to provisions on supervision and enforcement of the backstop as agreed by Theresa May "which meant accepting the jurisdiction of the European Court of Justice in Northern Ireland whenever EU rules applied."

Despite the UK’s threats to leave the EU without a deal at the end of October 2019, Mr Johnson appeared to accept the EU’s position that there could not be a customs border on the island in exchange for a new consent clause involving the assembly.

That arrangement emerged during the Liverpool meeting with Mr Varadkar on 10 October.

Mr De Rynck says that on the eve of the Liverpool meeting, Mr Johnson told Mr Varadkar by phone that Northern Ireland would stay de jure in the UK customs territory, but de facto in the EU’s customs territory.

This "changed everything," writes Mr De Rynck, as it meant there would be no customs or regulatory checks on or near the Irish land border.

"To the EU [Johnson] seemed to be looking for an agreement by giving Northern Ireland …a different treatment compared to Great Britain on customs, not just on regulatory issues."

In Liverpool, according to the book, Mr Johnson also confirmed to Mr Varadkar that the all-island economy would be protected.

In July, Mr Johnson’s negotiator David Frost had told EU officials that the UK no longer believed the all-island economy had to be protected.

"Irish diplomats present in Liverpool informed Barnier’s team by phone of Johnson’s U-turn on the all-island economy," Mr De Rynck writes, "since he told the Taoiseach that the all-island economy would not just keep ‘functioning’ after Brexit, but also ‘deepen’.

"Varadkar had explicitly confirmed with Johnson that he could say this publicly."

A week after the Liverpool meeting, Mr Johnson and the EU concluded the Withdrawal Agreement, including the Northern Ireland Protocol, at an EU summit in Brussels.

Six weeks later Mr Johnson won a landslide majority on the slogan that he had "got Brexit Done".

Mr De Rynck concludes: "Anyone speculating that the threat of no deal by the UK would panic the EU into throwing Ireland under the bus or change its position misread the EU. Yet Downing Street sources kept feeding reporters with that line."