Russia and Ukraine have settled a row over gas prices which disrupted supplies to several European countries.
Russia says gas supplies to Europe have now been fully restored
Under the five-year deal, Ukraine will buy Russian and Central Asian gas for $95 per 1,000 cubic metres on average.
Russia halted gas supplies to Ukraine on 1 January, after Kiev rejected a price rise that would have taken the cost of gas from $50 to $230.
The European Union said it would have to "learn the lessons" and find ways of improving security of energy supplies.
The head of Russian energy company Gazprom told reporters in Moscow a final agreement that was "successful" for Gazprom.
"This agreement will ensure stable supplies to Europe," Alexei Miller said.
Austrian Energy Minister Martin Bartenstein told journalists in Brussels that Russian gas would remain the backbone of the European energy supply mix.
But he said: "We have to think about energy supply security in general, gas supply security... and we have to learn the lessons."
He added that a planned pipeline to deliver Caspian gas to Europe via Turkey could help to diversify the EU's sources of gas.
Russia supplies about a quarter of Western Europe's needs, but this proportion is due to rise dramatically in future, on current plans.
Delegates from Ukrainian state energy company Naftogaz held midnight talks with Gazprom executives to try to resolve the dispute.
Under the compromise, Ukraine will buy gas from the Swiss-registered trading company Rosukrenergo, which is half-owned by Gazprom.
Gazprom will sell Russian gas to Rosukrenergo for $230 for 1,000 cubic metres from 1 January, but the company will also supply Ukraine with much cheaper gas from Turkmenistan.
The overall price Ukraine will pay will be $95 per 1,000 cubic metres. It will also get paid 47% more for transporting Russian gas to Europe.
Previously, Ukraine bought gas from both Turkmenistan and Russia at a price of $50 per 1,000 cubic metres.
Analysts say the deal is a face-saving compromise for the two sides.
"It's designed so that both sides can say they're paying - and being paid - the price they wanted," Stephen O'Sullivan from Moscow investment bank UFG told the BBC News website.
The Ukrainian foreign ministry said the authorities were fully satisfied with the deal and it was a clear victory for the country.
However, Prime Minister Yuri Yekhanurov said Ukraine had learnt that it must boost energy efficiency in order to reduce gas consumption.
The Reuters news agency says that under the deal, Ukraine will buy less Russian gas than before - 17bn cubic metres per year - and more than 40bn cubic metres from Turkmenistan and Kazakhstan.
Mr Bartenstein, whose country holds the EU presidency, said energy would be a high priority of the EU's March summit.
He asked the European Commission to submit a plan for an improved energy policy, looking at security of supply, competitiveness of prices, and possible further investment in the energy sector.