Former Greek Finance Minister Yanis Varoufakis

Greece's far-left former finance minister Yanis Varoufakis called Sunday on the next leader of Spain to defy the European Union, speaking to hundreds of cheering onlookers during an anti-austerity gathering in Madrid.

The so-called "Plan B" weekend event near the grounds of Madrid's former abattoirs -- now converted into a sprawling cultural centre -- saw activists, actors and left-wing politicians from Spain, France, Britain and other countries get together as a pan-European movement against EU-imposed austerity gathers pace.

It comes at a time of uncertainty for Spain where December elections produced a hung parliament, as voters fed up with years of crisis-sparked austerity snubbed the traditional conservative and socialist parties and flocked to two new groupings -- centre-right Ciudadanos and far-left Podemos.

"A little bit more than a year ago... the Troika tried to convince the Greek people that the Spanish austerity programme was a success story," Varoufakis told the crowd, referring to the European Commission, International Monetary Fund and European Central Bank.

"We did not buy that lie," he said, pointing to the Greek elections in January 2015 that swept the radical left-wing Syriza party to power.

"In December, the Spanish people were told that if you do as we did, you will be crushed.... The Spanish people did not buy that lie," he said.

"This is why we are at now at a crucial juncture in Spain."

Socialist party chief Pedro Sanchez has been tasked by the king with forming a government after acting conservative Prime Minister Mariano Rajoy failed to get enough support from other parties.

He is currently trying to garner the backing of other groupings that won parliamentary seats, including Syriza ally Podemos, before a crux vote of confidence at the beginning of March.

"I don't care who is in government. What I care about... is that the next government respects the demands of the Spanish people for change and goes to Brussels and says 'no pasaran'," Varoufakis said.

Rajoy's tough spending cuts and tax rises during his four-year term helped Spain emerge from a severe economic crisis, but critics say he left glaring inequalities in his wake.

Madrid's "Plan B" anti-austerity gathering follows a similar gathering held in Paris last month.

Varoufakis himself launched a pan-European grassroots political movement to "democratise" the EU earlier this month.