The long-awaited agreement is a political triumph for Russian President Vladimir Putin, who is courting partners in Asia as those in Europe and the United States seek to isolate him over Moscow's annexation of Ukraine's Crimea peninsula. (Agencies)
Commercially, much depends on the price and other terms of the contract, which has been more than a decade in the making.
China had the upper hand as talks entered the home stretch, aware of Putin's face-off with the West.
But both sides could take positives from a deal that will directly link Russia's huge gas fields to Asia's booming market for the first time - via thousands of miles of new pipeline across Siberia that form part of the package.
"This is the biggest contract in the history of the gas sector of the former USSR," said Putin, after the agreement was signed in Shanghai between state-controlled entities Gazprom and China National Petroleum Corp (CNPC).
"Our Chinese friends are difficult, hard negotiators," he said, noting that talks went on until 4 a.m.
"Through mutual compromise we managed to reach not only acceptable, but rather satisfactory, terms on this contract for both sides. Both sides were in the end pleased by the compromise reached on price and other terms," the president said.
Putin and Chinese counterpart Xi Jinping applauded as they witnessed the deal being signed before the Russian leader was to leave Shanghai at the end of a two-day visit.
The agreement came in time for a major economic summit in St. Petersburg starting Thursday. About a dozen chief executives and chairmen of major U.S. and European firms have withdrawn from the forum over the Ukraine crisis.
Putin loyalist and senior parliamentarian Alexei Pushkov, who was included on a U.S. list of sanctions imposed in the wake of the crisis in Ukraine, said the gas deal showed Russia could not be isolated.
"B. Obama should abandon the policy of isolating Russia: it will not work," he tweeted, referring to US President Barack Obama, who has pushed for greater Western punishment of Russia.
The long-awaited agreement is a political triumph for Russian President Vladimir Putin, who is courting partners in Asia as those in Europe and the United States seek to isolate him over Moscow's annexation of Ukraine's Crimea peninsula.