Lawmakers voted 187 to 161 in favour of the decree, which came into effect on August 10 but needed the green light of the assembly to remain in force.
Socialist Prime Minister Pedro Sánchez’s minority coalition government lacks a working majority in parliament but it managed to pass the rules with the support of smaller regional parties.
“Common sense, healthy politics and policies that defend the general interest triumphed today in parliament,” Sánchez told a press conference in Quito where he was on an official visit after the vote.
Under the government decree, air conditioning must be turned down and set at no lower than 27 degrees Celsius (80.6 degrees Fahrenheit) during the warmest months of the year, in rules affecting everything from public transport to shops, offices, theatres and cinemas.
The new rules do not apply to home air conditioning, although people are encouraged to consume less energy domestically.
During the summer months, temperatures across Spain often hit 40C or higher.
The legislation also affects heating in winter, when temperatures can be set no higher than 19C.
The decree also requires that from 10:00 pm (2000 GMT), shops switch off window-display lighting in a move also affecting the illumination of public buildings.
By the end of September, any air-conditioned or heated premises must have an automatic door-closing mechanism installed to avoid energy waste.
The main opposition conservative Popular Party (PP) voted against the measures, calling many of them “improvised” and harmful for the economy.
It also complains the new rules were developed without business groups or regional governments which will have to monitor compliance.
Among the most critical has been Madrid’s regional leader Isabel Díaz Ayuso, a rising star on the political right who has vowed to challenge the measures in Spain’s Constitutional Court.
“Madrid will not switch off,” she said earlier this month in a tweet.
The government unveiled details of the energy saving measures in May as part of an EU-wide effort to cut dependence on Russia for oil and gas following its February invasion of Ukraine.
The European Commission is planning to cut EU dependency on Russian gas by two-thirds this year and end its reliance on Russian supplies of the fuel before 2030.
Spain barely uses Russian gas itself, but by reducing energy use the government hopes to free up gas Madrid normally buys from countries other than Russia for nations trying to wean themselves off Russian supplies.
The measures show Spain’s “commitment and solidarity with our European partners in the face of the energy blackmail” from Russian President Vladimir Putin.
To boost the chances that parliament would back the energy saving measures, they were included in an omnibus bill which included other popular measures such as free commuter rail travel.
All commuter trains run by national rail operator Renfe will be free for four months from September 1st to help people cope with rising fuel prices.
Some 400,000 people have already signed up for the free travel pass, the government said Thursday.