Hungary and Poland opposed the law, but their opposition did not derail the plan, which needed support from a reinforced majority of 15 countries to become law.
European Union countries have formally adopted the bloc's emergency plan to curb gas use as they attempt to save fuel for a winter of uncertain Russian supplies, despite Poland and Hungary both opposing the final law.
The bloc last week struck a deal to reduce their gas demand, to attempt to fill gas storage and prepare for a possible full Russian cut-off. On Friday, they formally approved the law that will put this deal into action.
The agreement asks all EU countries to voluntarily cut gas use by 15 percent this winter and could make the cuts binding in a supply emergency, albeit with numerous opt-outs for some countries and industries.
All countries except for Hungary and Poland approved the law, according to a document published by the Czech Republic, which currently chairs EU country negotiations.
A reinforced majority
Before its offensive on Ukraine, Russia provided 40 percent of EU gas. Moscow has since slashed gas flows to Europe, making it harder for EU states to fill storage ahead of winter, and prompting many to race to buy non-Russian fuel and take steps to limit their gas demand.
Hungary, which is in talks to buy more gas from Russia, was the only country to oppose the deal last week and questioned the legality of EU rules that affect a country's national energy mix or energy security.
Poland also opposed the final law, despite supporting the deal last week. Poland described the legal basis for the law as "defective", and said decisions affecting the energy mix of member states should be taken with unanimous approval from all countries.
Their opposition did not derail the plan, which needed support from a reinforced majority of 15 countries to become law.
The European Commission is also "urgently assessing" the possibility of introducing gas price caps, it said in a statement, without elaborating on what form such a cap would take.