The lamps may not be going out all over Europe, but they’re flickering. The continent is being tugged in different directions by competing forces, and it is unclear who will succeed. Two potentially historic events this week will help define its future.

On Thursday Britain could choose to become the first nation to leave the European Union, the consequence of a campaign dripping in bigotry and the scapegoating of migrants. And on Sunday Spain goes to the polls for a re-rerun of an inconclusive election in December. The newcomer Unidos Podemos party, standing on a platform of opposing cuts and democratising Spain and Europe, is attracting the support of millions of Spaniards. The votes highlight the competing visions of Europe’s future.

There are three philosophies at play right now. The first blames migrants and people fleeing violence and poverty for the multiple problems afflicting European society, from the lack of secure jobs and houses to stagnating living standards to public services ravaged by cuts. The second seeks to build a Europe with shrivelled social protections, run ever more in the interest of major corporations, as exemplified by the notorious but embattled Transatlantic Trade Investment Partnership. These two visions are far from mutually exclusive; they are frequently allied, or feed off each other. The third vision challenges them both: holding the powerful interests responsible for Europe’s crisis to account, and aspiring to a democratised Europe that puts people before the needs of profit.

If we decide to leave, the odds of an EU collapsing amid anti-immigrant acrimony will increase

I left Britain’s poisonous referendum campaign for a few days to travel across northern Spain with Unidos Podemos. It didn’t feel so much like entering another country as passing into a parallel universe. Spain shows there is nothing inevitable about people blaming migrants, rather than the people in charge, for their problems. And when it comes to problems, Spain is not lacking. A fifth of its workforce is unemployed, and nearly half of its young people are without work. Hundreds of thousands of Spaniards have been evicted from their homes. Child poverty has risen. Public services have been slashed. Yet in the working-class town of Torrelavega a crowd roared with approval when told the problems facing Europeans are caused not by foreigners but by bankers, tax-dodgers and poverty-paying bosses.

There is no mass anti-immigration party contesting Spain’s elections. Mainstream parties are not trying to outdo each other with anti-immigration vitriol. It is not as though there is a lack of people entering the country: Spain experienced a sixfold increase in migrants in the 2000s. Immigration is simply not the prism through which people understand their problems.

Facebook Twitter Pinterest ‘There is no mass anti-immigration party contesting Spain’s elections’ Photograph: Vincent West/Reuters

Why? The memory of General Franco’s dictatorship adds a layer of revulsion for the far right in the eyes of many Spaniards. Similarly, a history of Spanish emigration because of dictatorship, poverty and economic insecurity might mean more sympathy for people who travel to build a new life. But senior Podemos figures dismiss the idea that Spanish society is somehow culturally immune to anti-immigration hostility. Instead they point to the rise of the so-called 15-M movement in 2011.

An initial call on 15 May 2011 for Spaniards to mobilise against the country’s political establishment attracted thousands of protesters. It was the catalyst for a phenomenon that has transformed Spanish politics. Over the course of many months, millions of Spaniards took part in protests and occupations.

It was this movement that laid the political foundations for the rise of Podemos. Its critical contribution was to ensure that the focus of Spanish anger was the powerful, rather than migrants. Podemos activists believe that without this movement, Spain could also have succumbed to anti-immigration sentiment.

Concerns about immigration should be debated. But in contrast to Spain, so many of Britain’s problems are seen through the prism of immigration. The failure of a popular movement to organise meant that an alternative explanation for social ills never gained traction. Immigration was already the catch-all explanation for grievances; the referendum has only entrenched this view.

Across Europe, the visions represented by the rightwing Brexiters in Britain and Podemos in Spain are locked in combat. If Britain leaves the EU as the result of a campaign whose core message is hostility to migrants, that will be a shot in the arm to already ascendant anti-immigration movements across Europe.

The question isn’t whether France’s far-right leader Marine Le Pen will celebrate Brexit, but how expensive will be the champagne she chooses to toast it with. The odds of the EU disintegrating amid anti-migrant and anti-refugee acrimony will increase. If Unidos Podemos do well in Spain on Sunday – and even forms a coalition government with the Socialists – then that will be a significant boost to movements arguing for a Europe of public investment and workers’ rights.

We must remain: if you're undecided, here's my final plea | Jonathan Freedland Read more

Europe has now endured years of cuts, regressive tax hikes and stagnating or falling living standards. The xenophobic right has feasted on the despair and grievances that have resulted. The antidote is movements such as Podemos: those that redirect anger at the correct targets, and propose an alternative Europe that doesn’t breed insecurity. Greece’s Syriza government was cowed by the EU because the bureaucrats could do so: Greece represents a tiny sliver of the eurozone economy. Spain, by contrast, can’t be bullied in the same way: it is “too big to fail”.

Our own government has led the attempts to drive the EU ever more down the road of servility to the interests of the market – by vetoing EU action to prevent Chinese steel-dumping, for example, and being the biggest cheerleader for TTIP. That direction of travel makes the work of movements such as Podemos even more vital.

There have been many significant postwar moments in Europe, not least the fall of the Berlin Wall. But set against that backdrop, this remains a defining moment. Are we to have a disintegrating Europe characterised by widespread, destructive, anti-migrant resentment, corporate dominance and shredded social protection, or a democratic Europe run in the interests of the majority? The people of Britain and Spain can light the way.