MOSCOW  The prime ministers of Russia and Ukraine agreed Sunday to resolve their gas dispute, with an understanding that prices would be pegged to the price of oil, but with a discount for 2009 that means Ukraine could pay little more than it did last year.

The deal, expected to be signed Monday, came after a din of criticism from officials in Europe, where more than 20 countries have been affected since a Jan. 6 cutoff of natural gas and at least 12 people have frozen to death in a dispute that is ostensibly over prices and transit fees, but that is also deeply entwined in post-Soviet politics.

If the agreement holds  and previous deals have not  the gas dispute would essentially end where it started in terms of prices, in what would be a baffling result considering the hardship caused by the embargo. It was unclear after the announcement when gas would start flowing back to Europe.

Politically, Russia appeared to have made gains in influencing internal Ukrainian affairs ahead of an election scheduled there next year, but at the cost of alienating officials in European countries in a standoff that was as much geopolitical as commercial.