SHANGHAI-  China and Russia signed a long-awaited, $400-billion gas supply deal today, securing the world's top energy user a major new source of cleaner fuel and opening a new market for Moscow as Europeans look elsewhere for their energy.

Russian President Vladimir Putin and Chinese counterpart Xi Jinping applauded as they witnessed the deal being signed in Shanghai between state-controlled entities Gazprom and China National Petroleum Corp (CNPC).

The deal is a political triumph for Putin, who is courting new partners in Asia as customers in Europe attempt to reduce their reliance on Russian gas to bolster their bargaining positions with Moscow after its seizure of Crimea from Ukraine.

But from a commercial point of view, much depends on the so far undisclosed price and other terms of the contract, which has been more than a decade in the making.

Industry insiders said China had the upper hand in negotiations as they entered their final phase, aware of Putin's need for new customers as his isolation in Europe intensified.

"This is indeed a historic event for the gas sector of Russia and of the Soviet Union," he said. "This is the biggest contract in the history of the gas sector of the former USSR.

"I want to stress that there was hard work done on the expert level. Our Chinese friends are difficult, hard negotiators," he said, noting that negotiations 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."

Another potential sticking point has been whether China would pay a lump sum up front in order to fund considerable infrastructure costs.

The gas will be transported along a new pipeline linking Siberian gas fields to China's main consumption centres near its coast. Russia will begin delivering from 2018, building up to the annual target of 38 billion cubic metres, officials said.

Putin announced that Russia planned to invest $55 billion in exploration and pipeline construction up to China.