BORIS Johnson spent the early hours of Friday morning considering his bid for the Tory leadership, but the real referendum winner was enjoying a drink at Millbank Tower in London.

UKIP leader Nigel Farage, a seven-time loser at Westminster elections, had spent his entire political career trying to crowbar the UK out of the EU and he had now succeeded.

As the polls closed, he was sombre as he told friends he expected a narrow win for the Remain camp.

But when the result from Sunderland came through – a 61% vote for Leave – the mood turned and UKIP sensed victory was looming.

Farage’s party – through a toxic blend of populism and xenophobia – had helped turn a referendum on the EU into a straight vote on immigration; even a referendum on race, some would say.

UKIP’s message had helped peel away socially conservative Labour voters with a message that was as offensive as it was effective.

Despite one of the most fevered campaigns in living memory, it is easy to forget there was little public support for a referendum in the first place.

Voters never listed an EU referendum as a priority and it was only ever a favoured subject of pub bores and cranks.

But David Cameron, captive to the Tory Right and wary of UKIP’s rise, suicidally made it a manifesto commitment to appease restless colleagues.

Europe had brought down Thatcher, tormented John Major and acted as a nuisance to his successors. The Prime Minister wanted closure, but in the end he signed his own political death warrant.

However, senior campaign sources on the Leave side have told the Sunday Herald that the victory came in spite of divisions on strategy and tactics.

A permanent handicap during the campaign was the presence of two competing anti-EU groups whose members had contempt for each other.

Vote Leave, the official campaign body, gave the impression of being cross-party, but was essentially an organisation run by Thatcherite Tories whose opposition to the EU was ideological and long-standing.

Dominic Cummings, a former special adviser to Michael Gove, was the group’s campaign director and has been described by former Liberal Democrat Minister David Laws as “a grade-A political Rottweiler”.

The chief executive of Vote Leave, Matthew Elliott, was also from the radical Right and the brains behind the Taxpayers Alliance, a group committed to deep cuts to spending and tax.

The Tory MPs they had on tap – Priti Patel, Chris Grayling, Michael Gove – were all, to varying degrees, similarly-minded. They preferred talking about economics and sovereignty to discussions on foreigners.

It was also a traditional ‘command and control’ campaign: centrally-determined messages honed from focus groups; a blizzard of press releases; and a well-financed war chest.

Vote Leave was also disciplined. Head of Ground Campaigns Nick Varley chaired a conference call every Monday, Wednesday and Friday with the group’s regional directors.

By contrast, UKIP and Grassroots Out (GO) – a Farage front group – put boots on the ground and were committed to changing the referendum conversation to immigration from the EU.

Although Vote Leave won the right to be the Out campaign’s official voice, the tension between Elliot’s team and Farage persisted even after the polls had closed.

The groups fought for the same goal, but niggles about TV slots dogged the Brexit side and there was little contact between the apparatchiks on both sides.

UKIP/GO insiders told the Sunday Herald that Vote Leave went to “ridiculous” lengths to try to marginalise Farage.

“It started when they briefed against us at our own conference in Bournemouth,” a UKIP source said.

Another source said Vote Leave threatened to boycott ‘Brexit: the movie’ unless Farage was dumped.

The paranoia about Farage reached its peak when ITV successfully organised an EU debate involving the UKIP leader and David Cameron.

“Vote Leave wanted to go to court to stop it. They hated Nigel getting any attention,” an insider said.

The Brexit campaign suffered from the same division north of the border

Vote Leave was led in Scotland by former Labour Minister Tom Harris, who was insistent that the clownish David Coburn, UKIP's sole MEP north of the border, should have no role.

At the Scottish launch in Glasgow, where Tory Cabinet Minister Theresa Villiers was the keynote speaker, Harris physically prevented Coburn from getting into the event.

Coburn recalls: “I turned up because I was the most high-profile Eurosceptic in Scotland. And I was told to take a walk by Tom Harris.”

A source in the Scottish campaign also believed UKIP/GO figures were attending Vote Leave events on the sly and undermining the strategy: “People were coming to training events and saying 'you don't need to canvas voters, it’s a waste of time’.” The same insider described UKIP as the “serpent in the garden”.

There were also tensions inside Vote Leave with sensitivities about the negative effect the referendum would have on the Tory party running high.

On one level, this was absurd: a large part of the campaign amounted to an extended psychodrama between Cameron and Johnson.

However, some Out supporters believed senior Vote Leave figures saw Brexit as a way of repositioning the Conservatives, rather than simply being about saying goodbye to the EU.

One GO insider said: “All the Vote Leave guys will want jobs in a future Conservative Government, so they don’t want the party to fall apart.”

As proof of this theory, Vote Leave uncovered footage of Cameron saying he wanted to “pave the road from Ankara to Brussels”, a find that confirmed the Prime Minister was sympathetic to Turkey joining the EU.

However, although the ‘evidence’ was found months ago, Vote Leave decided against using it as a weapon until after the May’s local elections.

“It was held back so that the Conservative Party’s chances at the local election were not damaged,” one Vote Leave figure explained.

In the end, the great irony of the Brexit campaign was that immigration – the top issue for UKIP/GO, not Vote Leave – proved to be the referendum trump card.

According to insiders, the roots of this divide – immigration versus the economy – could be traced back to 2015.

Elliott, at that point the leader of Business for Business, which begat Vote Leave, saw the economy as the gateway argument for Brexit.

His strategy was to ask business leaders to sign a pledge calling for a renegotiated deal with the EU, followed by an In/Out referendum

In the other corner was tycoon Aaron Banks - the co-founder of the Leave.EU organisation - who wanted a greater emphasis placed on immigration.

When the Electoral Commission unveiled Vote Leave as the official ‘designated’ campaign body in April, the Elliott plan won by default.

However, his strategy of making the economy the key plank of the euro-sceptic case failed miserably.

A range of experts, from the governor of the Bank of England to economists and business leaders, argued that leaving the EU would reap economic trouble.

By the end of May, with barely a month to go, Remain led on the economy and the polls looked bad for Brexit.

It was against this backdrop that Vote Leave changed tack and put immigration at the front and centre of the campaign.

In UK general elections, a loose 'gentleman’s agreement' tends to prevent the two main parties from making border control the key campaign issue.

With time running out, Vote Leave changed tack and hammered away at immigration.

At a glance, the Vote Leave approach to the potent issue seemed more sophisticated than the brutish language used by UKIP and their fellow travellers.

For Elliot and co, uncontrolled migration was pitched as a threat to wages and public services. Framing Brexit as a way of “taking back control” over the number of incomers was also politically astute.

But while UKIP got slaughtered for its racist poster of a queue of brown-skinned refugees under a ‘Breaking Point’ slogan, Vote Leave was just as cynical in politicising migration.

Of 54 Vote Leave press releases in the first three weeks of June, 38 mentioned ‘migrants’, ‘migration’, ‘immigration’ or ‘Turkey’ in a negative way.

The official campaign body also released an image of the terrorist supporter Abu Hamza as part of its anti-EU approach.

The ‘bad cop, terrible cop’ strategy was effective. Vote Leave had taken a drubbing on the economy, but the average voter, for good or ill, believed Brexit meant fewer immigrants. With a week to go, Leave was in the lead.

However, the momentum generated in one of the most fevered campaigns in British political history shuddered to a halt on June 17th.

Jo Cox, a Labour MP who had spoken of her support for immigration, died after being shot and stabbed in her constituency. Her killing came amid the controversy over the ‘Breaking Point’ billboard.

Several pro-Brexit campaigners feared Cox’s death would derail the campaign.

“It took the sting out of the immigration issue,” one said. “Nobody seriously blamed us, but it created a new mood.”

The polling numbers started to look better for Remain, but the shift was not strong enough to halt the Brexit surge.

Even after the victory was confirmed, the tensions between Vote Leave and Farage flared up again.

In one of many interviews, the UKIP leader disputed the official campaign group's claim that Brexit would generate an extra £350million a week for the NHS.

The UKIP leader said: “I would never have made that claim. That was one of the mistakes that I think the Leave campaign made.”

Leave’s political legacy can be seen in two ways: the personalities; and the policies.

The result immediately triggered Cameron’s resignation and will likely lead to Johnson becoming the next Prime Minister.

Labour MPs are also furious with leader Jeremy Corbyn for his lacklustre campaign and are plotting a motion of no confidence in him.

By contrast, the future of UKIP looks to be brighter. A party of eccentrics and angry old men has now become the voice of a populist movement that has rocked global politics.

UKIP's ruthless focus on immigration chimed with socially conservative Labour voters, while Labour’s “workers’ rights” message barely registered.

Several Labour sources told the Sunday Herald they fear that the drift of the party’s supporters to UKIP – evident at the last general election - will be accelerated.

However, it is the unleashing of immigration as the UK's top political issue that may stand as the poisoned legacy of the referendum.

The Brexit campaign failed to land any meaningful hits on the economy, but still won through a relentless focus on the number of migrants coming to Britain.

Politics in the UK has moved to the Right – any party that bathes in the swamp stands to reap electoral rewards.