"There is now no reason for people in Europe to stay cold this winter,'' said European Commission President Jose Manuel Barroso.
European Union energy chief Guenther Oettinger said he was confident that Ukraine would be able to afford to pay for the gas it needed.
He added that the agreement might be the "first glimmer" of hope in easing tensions between Russian and Ukraine.
Gas supplies were halted over late payments when Russia scrapped subsidies given to Ukraine for importing gas, meaning the price paid by Ukraine rose sharply.
However, the backdrop to the row is Russia's conflict with Ukraine and Western sanctions on Moscow.
Although the impact of the gas ban has been relatively small, the onset of winter made the need for a deal more urgent.
Ukraine has relied on Russia for around 50% of its gas. Despite storage facilities Ukraine has a winter shortfall of around 3 billion to 4 billion cubic metres of gas, analysts say.
Russia provides around a third of the European Union's gas, about half of which is pumped via Ukraine.
Russia's Energy Minister Alexander Novak told a news conference that the deal secures supplies for Ukraine and Europe.
"I want to reassure you that Russia has always been a reliable supplier of energy resources to Europe and other consumers.
It has been, is and will be a reliable supplier.
"The autumn and winter period is safe (for Ukraine) and the supply to European consumers is also stable. We are convinced that our future relations will be constructive and that our agreements will be fulfilled," he said.
Ukraine's Prime Minister Arseniy Yatseniuk said that the EU had agreed to serve as guarantor for the gas price Kiev would pay to Russia.
Ukraine will pay $378 per 1,000 cubic metres to the end of 2014, and $365 in the first quarter of 2015.
Mr Yatseniuk said Kiev was ready to pay off debts for gas immediately after any deal was signed.
A total of $1.45bn would be paid immediately, and another $1.65bn by the end of the year, he said.
Mr Novak insisted that Ukraine would still have to pay in advance for new deliveries.
Mr Oettinger, who steps down as European energy commissioner on Friday, said: "We can say to the citizens of Europe that we can guarantee security of supply over the winter."