Europe's refugee crisis has become a popular cause for Spain's left-wing leaders, who are channelling public sentiment to pressure the government into a more generous stance.
City halls, charities and impromptu Facebook groups are marshalling offers of aid and urging the government to open Spain up to refugees who are risking their lives to reach Europe from trouble spots such as Syria.san
"I am proud of the expressions and initiatives of solidarity by so many Spanish people in response to these tragedies," wrote Prime Minister Mariano Rajoy, responding to an open letter from Barcelona mayor Ada Colau.
Accused by the left of dragging its feet as Europe faces its worst refugee crisis since World War II, the government on Tuesday agreed to take in however many the European Commission demands - a figure likely to be around 15,000.
The apparent change in policy comes after months of action by city councils and concerned citizens, many organised by groups linked to Spain's anti-austerity "Indignado" movement.
On August 29th, Colau called for the establishment of a "network of cities of refuge to give a home to thousands of civilians fleeing from war".
Since then, more than 100 cities have taken up the call, among them Madrid, Valencia and Zaragoza, the mayor said, adding: "While states look for excuses, the cities have got organised."
In Madrid, a huge white banner reading "Refugees welcome" was hung outside city hall this week, and Mayor Manuela Carmena has pledged €10 million ($11 million) to receive migrants in the city.
Across Spain, countless citizen groups have also sprung up to support the refugees.
One in the northern region of Asturias says it has received thousands of messages of support since launching on Facebook last week.
'Tired of just crying'
"It's incredible," said one of the organisers, Betty Menendez, a 35-year-old housewife.
"We have 350 families that are ready to host and another 400 offers of help of all kinds: lawyers, dentists, doctors, translators, carers, Spanish teachers, everything."
Menendez said she was "tired of just crying at the news on television".
She and her husband are now offering to put up a refugee in their 54-square-metre (80-square-foot) apartment in the bedroom normally occupied by their 18-month-old toddler.
"The house is very small, but we would give them food, a bed and a shower, and the freedom to come and go," she said.
European Commission chief Jean-Claude Juncker will on Wednesday unveil a plan for urgently resettling 120,000 migrants across EU member states, with Germany likely to take in more than 31,000, France some 24,000, and Spain almost 15,000, a source told AFP.
Until Tuesday, Rajoy's conservative government, which is to contest a general election in December, and insisted it would only take in 2,739 refugees this year.
In response, more than 245,000 people signed a petition on the website change.org calling on the Spanish government to "immediately open the doors to refugees".
In an apparent U-turn, Deputy Prime Minister Soraya Sáenz de Santamaría on Tuesday said that "Spain will accept the number of refugees that the European Union asks us to take".
With a population of nearly 47 million, Spain accounts for 9.1 percent of the EU's population, but last year it took in less than one percent of the bloc's asylum applications, UN figures showed. In all, it granted refugee status to just 384 people.
Monica Oltra Jarque, deputy leader of the Valencia region and a member of the left-wing party Compromis, said there was room in Spain for plenty more.
"If each Spanish town took just one family, we could host 20,000 families," she said.
By Linh-Lan Dao