The Spanish parliament approved a clean energy bill on Thursday (13 May), aiming to achieve carbon neutrality by 2050 in line with EU-level ambition and banning the sale of fossil fuel vehicles by 2040.
The law will see the sale of CO2 emitting vehicles outlawed by 2040 and their circulation stopped by 2050 in order for the country to meet its carbon emissions target.
"For the planet, for our future and for the next generations. From today, Spain has a climate law on which to build a green, sustainable, fair and prosperous future for all," Prime Minister Pedro Sanchez tweeted after the vote.
The overall aim is to implement measures that will enable Spain to meet the European Union's target of achieving carbon neutrality by 2050. It also sets a national 2030 target for reducing greenhouse gas emissions by at least 23% compared with 1990 levels.
The law also limits new coal, oil and gas extraction projects and requires that, by 2030, renewables account for 42% of Spain's total energy consumption and at least 74% of its electricity production.
And it stipulates that, within two years, all towns or cities with more than 50,000 residents must have low-emission zones such as those in Madrid and Barcelona.
The ban on most petrol and diesel cars from the centre of the Spanish capital, dubbed "Madrid central", was recently overturned by the courts.
In a tweet, Spanish Energy and Environment Minister Teresa Ribera called it an "essential law which we must continue to build on."
However, in an interview with El Pais published on Thursday, she admitted that Spain was behind the times with the law, saying it "should have been put in place 10 years ago".
And Greenpeace said the law did not go far enough. Its objectives, according to the NGO, were "inadequate for complying with the (2015) Paris climate accord" under which nations agreed to keep the planet's temperature within 1.5°C of pre-industrial levels.
"The text is a starting point that will need to be reinforced to successfully tackle climate change in a European country that is one of the most vulnerable to its harsh consequences," it said.
"Only by increasing its emission reduction targets will Spain be able to decisively combat the climate emergency," it added.