The whole thing going on with immigration did seem a bit the key of why people were pushing for Brexit. One of the British commentators I follow - a gay libertarian named Milo Yiannopolous - noted that there was a Gallup poll detailing the attitudes of Muslims living in the UK. According to the pool, out of 1000 British Muslims:
52% said homosexuality should be illegal (vs 11% of the general population)
47% said gays shouldn't be allowed to teach in schools (vs 14%)
40% said that a woman should always obey her husband (vs 5%)
35% said that Jews had too much power (vs 9%)
Sociological commentary on the poll suggested that, in contrast to most trends, Muslims who leave the Middle East and live in the West do not become more liberal, but more conservative.
Now, this is but one specific aspect of what's been happening, but I think worry and fear of the possibility of allowing in more immigrants - whether or not they're refugees or simply economic migrants - who hold these attitudes. Not to mention the problems that I've been hearing with the failure of immigrants to assimilate into the national culture (which is one of the key components of a national identity, which you need to be a nation).
That's not really relevant to this discussion though... as the highlighted part indicates. Our status in or out of the EU has very little to do with how we handle immigration from the Middle East and demographically EU immigrants are more likely to be Roman Catholic than Muslim.
So, quick post-mortem.
1) In many ways this followed a similar pattern to the Scottish Independance referendum. One side needed to rely on urban centres and while they did well there it wasn't enough to make up for virtually the rest of the country going against them, especially with a relatively underperforming turnout in those places and some of the victories being far narrower than expected.
2) Both campaigns were pretty negative overall but at least the Leave side actually put forward a somewhat positive vision of what life outside the EU could be like. Pretty much all of the Remain campaign's arguemnts broke down to saying "listen, we're so rubbish we can't make it with the EU propping us up" and the closest thing to a positive statement on the EU from them was basically "yes, we know there's a lot wrong with it but we'll reform it eventually"... something we've been told for decades and lacking even more power when the attempts to reform by Cameron in the buildup to this got very few actual results. Now, those points may or may not be true... but it's hardly an inspiring message to take to the electorate.
3) Kythia's mentioned this above but Labour going AWOL for the majority of the debate meant that one could be mistaken for thinking it was an internal Tory referendum with UKIP popping up every weeks to make some stupid claim and get some headlines. There were centre right visions for life both in and out of the EU from the Conservatives and there were at least some centre left visions from the Labour figures who did support Leave but in terms of a centre-left vision really saying why we should stay in? Not so much.
4) Part of that is the fact that Labour (and the left in general) is caught up in a battle for its own identity that the EU serves as a great example of and appears more and more with each election. "Old Labour" had its powerbase with the traditional working class in industrial towns... the sort of people who are extremely worried by immigration and the like. But from at least Blair onwards Labour has had far more of a metropolitan, upper-middle class twist with a supporting act of immigrant and "minority" (for lack of a better term) communities. You can see that in the results here; the North East (traditional Labour heartland) was pretty heavily leave while London (modern Labour's heartland) was almost entirely remain.
5) More of an addition to the last point than a new one, you could see Corbyn's struggles to articulate or support his positions whenever he spoke; many of his interviews sounded more like a Leave campaign speech then for someone who wanted the UK to remain in. My suspicion is that in a free world Corbyn would have actually gone for leave himself but a combination of political advisors and a distate for sharing a platform with UKIP and the Leave side of the Tory party meant he bit his tongue and went through the motions of supporting the Remain campaign.
6) Whoever in the Remain campaign thought that getting foreign leaders/figures to deliver "stay in or else" type messages, even if they were far more polite and nuanced then that in reality, needs a big pay rise from the Leave campaign. I can't see how anyone thought that what could easily be presented as foreigners scolding the UK electorate to do what they're told would be a good idea.
7) Like him or hate him Cameron has previously proven himself one of the most effective campaigners in recent UK history; while he may not have always taken up official positions it wasn't exactly hard to spot that he supported what became the winning side in both the electoral system and Scottish independence referendums while also winning a shock majority in the last election. But effective campaigner or not, Cameron was outgunned and outnumbered here. Leave could bring out Farage for the attack dog stuff, Grove for the more "academic" approach or Johnson for bumbling charm. Remain? They had Cameron and that's about it when it comes to leaders. One man can only do so much... and it's a strange thing to think that Cameron was about 2% of the vote away from becoming one of the great statesmen of our time.