If David Cameron wins on Thursday by the narrowest of margins, he may well owe his salvation to his old enemies in the north. They will tilt the balance. So much of his own side is on the other side, working for his defeat.

He won’t owe victory to the Mail and he won’t owe it to the Sun; he won’t owe it to Rothermere or Murdoch; he won’t owe it to most of his own party’s activists or the fierce English patriots of Essex, Yorkshire and Kent. The electorate of Scotland will have saved him – and more than him, if we believe Cameron’s arguments. Sterling, high London house prices, low mortgages, the “war on terror”, George Osborne, the UK economy: all of these things will have been saved by the Europhile voters of Scotland, including those in poor places such as Coatbridge and Paisley, where prosperity can be remembered only by the over-70s and Ted Heath was the last Tory leader to be tolerated, never mind liked. If it happens, British political history will be hard pushed to furnish a bigger irony.

Opinion polls show that, though Remain’s majority in Scotland is shrinking, inners still lead outers among those likely to vote by 25%. In the UK as a whole, on the other hand, outers were leading this week by as much as 7%. To put the question crudely, why does Scotland like the EU more than England does – or, to be a little more accurate, why does it seem to want to leave it so much less?

An obvious answer is attitudes to immigration. By the standards of England and much of mainland Europe, Scotland remains a remarkably homogeneous country. According to the 2011 census, only 4% of its population is from ethnic-minority groups – double the percentage of 10 years before, but less than a third of the 14% for England and Wales. About 40% of London’s population is from a minority ethnic group; the figure for Edinburgh is 8%. As to first-generation migrants, 7% of the Scottish population was born outside the UK compared to 12% for the UK overall. Of the 853,000 Poles estimated to be living in the UK in 2014, only 55,000 settled in Scotland, a disproportionately small number for a country with roughly a 12th of the UK’s population.

But is a host population more tolerant of outsiders the fewer of them there are? Personal experience suggests the opposite may be the case: nobody in London ever suggested that an Indian friend of mine went “back to the trees”, but it came easily to the lips of a few local boys in the Scottish village I’d grown up in when I took her there 35 years ago; and, with every respect to English country life, a non-white individual is hardly likely to have an easier time of it in Norfolk than in Hackney.

It might be truer to say that immigration has made less of an impact in Scotland because it can be portrayed as a phenomenon or problem belonging to another country, with its roots in an empire in which Scotland, with a helpful amnesia, forgets it played a significant role. Suppressing or being ignorant of imperial history, rejecting the union flag, a Scot can present himself to an Indian, say, as a fellow victim of big bully England. The lie has one good result: it frees an individual from an awkward passage in his national history. For those still acting this memory out, see the English football fans running amok in the streets of France.

Then there are the newspapers. In Scotland, the London dailies and weeklies sell far more copies than their indigenous rivals – the Scottish edition of the Sun has the biggest circulation of all – but their power to shape the national conversation seems far weaker. “The Daily Mail reader” and “the Sun reader” are sociopolitical archetypes that belong south of the border. The Scottish editions of these newspapers tend to be watchful of a mainstream public opinion that they have played no part in creating, and sometimes even timorous towards it. “BeLEAVE in Britain and vote to quit the EU,” the Sun’s front-page editorial boldly urged Sun readers on Tuesday, though by Britain it must have meant England and Wales. The Sun’s editions in Scotland and Northern Ireland had different front pages that carried no such advice, large parts of which would be hostile towards it. Murdoch can only push his wisdom so far.

Other than in fishing and parts of the farming industry Brussels has never been successfully presented as a bogeyman in Scotland, thanks in part to the pre-existing bogeyman of London. It can even be argued that Scottish nationalism needed the EU to turn it into a successful movement, on the grounds that the “independent within Europe” policy, promoted by the SNP MP Jim Sillars in the late 1980s, made separation from the UK a less scary proposition and nationalists more electable. (Sillars himself is now one of Scotland’s few prominent Brexiters.)

But there are deeper elements at work here, dating from pre-union times when England’s continental enemies made Scotland a convenient friend, giving rise to the idea that Scotland has always been more “European” than England in its attitudes. Red pantile roofs from the Netherlands; the Scots word “ashet” meaning plate, from the French assiette: even in the 1950s Scottish schoolchildren were encouraged to see these slim pickings as evidence of continental rather than English influence. This amalgam of fact and feeling often lurks in the background when Scottish politicians imply, without any contemporary evidence, that Brussels is (or will be) more benign and generous to Scotland than London, or at least more politically in tune with it, and therefore a less problematic partner in sovereignty.

Finally, there is Robert Burns. In an interview with Alex Salmond seven years ago – it was the 250th anniversary of the poet’s birth – the then SNP leader spoke to me of how Scotland liked to see itself as a more egalitarian and community-minded country than its southern neighbour. Salmond didn’t necessarily accept this gratifying self-image as a fact. He described it as an “assumed identity” – a kind of national aspiration – and said he could think of no other country where a single cultural figure had done so much to form one, as Burns with his comradely poetry and perceived internationalism had done for Scotland. “Luckily, our assumed identity is rather an attractive one,” Salmond said. “We could have done a lot worse.”

Certainly, the consequences have been bad and good. On the one hand, an occasional outbreak of intolerable moral smugness; on the other, fans of the national football side who, when they lurch down foreign streets want, like drunken labradors, only to be liked. “That Man to Man, the world o’er, Shall brothers be for a’ that” is a sentiment that informs Scotland’s predilection for the EU. Who could have guessed it might save Cameron’s career, to say nothing of the UK’s future?