Negotiations on the 30-year deal were completed during a two-day visit to China by Mr Putin for an Asian security conference.
China's president called for a new model of Asian security co-operation based on a regional group including Russia and Iran and excluding the US.
The deal gives the Russian economy a boost at a time when Washington and the European Union have imposed visa bans and asset freezes on Russian officials and several firms over Ukraine. It lets Russia diversify its market for gas, which goes mostly to Europe.
Keun-Wook Paik, senior research fellow at the Oxford Institute for Energy Studies, said the deal gave Russia a "breathing space".
"Russia, and Putin, can demonstrate it's not completely isolated because of the Ukraine crisis," he said. "Russia has demonstrated they have a very reliable strategic partnership with China."
Russia's economy has been bruised by its dispute with the West over Ukraine's tilt towards the European Union, which inflamed Moscow's insecurities about declining influence and sparked its annexation of Crimea in March. The deal will ease gas shortages and cut reliance on coal in China, the world's second-largest economy.
Last week US treasury secretary Jacob Lew appealed to China not to undermine sanctions against Russia, but the US acknowledges China's pressing need for energy.
Alexei Pushkov, head of the international affairs committee of the Russian parliament's lower house, said on Twitter: "The 30-year gas contract with China is of strategic significance. Obama should give up the policy of isolating Russia: it will not work."
Mr Putin's visit to China is a "major step towards a strategic partnership of the two nations," said Mikhail Margelov, head of the foreign affairs committee in the upper house of Russia's parliament.
The Ukraine crisis and Western sanctions on Russia had raised expectations Moscow would compromise to secure the gas deal.Russia will invest £32.5 billion in fulfilling the contract. China will spend at least £11.8 billion.
The plan will mean building a pipeline to link China's north-east to a line that takes gas from western Siberia to the Pacific port of Vladivostok. It will let Russia export to Japan and South Korea.
"It will be the world's biggest construction project for the next four years," Mr Putin said.
l Chinese state media labelled the US a "mincing rascal" and "high-level hooligan" yesterday after Washington charged five Chinese military officers with hacking US firms to steal trade secrets.
The indictment was the first criminal hacking charge the US has filed against foreign officials, and follows a growing confrontation between the world's two biggest economies over cyber espionage.
In response China suspended a Sino-US working group on cyber issues. An editorial in the official Global Times said : "We should take further actions."
Yesterday a senior Chinese internet security official withdrew from an American Chamber of Commerce event where he had been due to speak on "the current global deficit of trust on cybersecurity".