China and Russia signed a monumental, multi-decade gas supply contract in Shanghai on Wednesday, Chinese state energy giant CNPC said, with reports saying it could be worth as much as $400 billion.

The contract signatures came after years of negotiations and were witnessed by Chinese President Xi Jinping and visiting Russian leader Vladimir Putin, CNPC said in a statement.

"This is another major milestone achievement in China-Russia energy strategic cooperation," it said, adding it was "facilitated and greatly supported personally by the leaders of China and Russia".

Russia has vast energy reserves and China is constantly seeking resources to power the growth of its economy, but the neighbors had been unable to agree a price for years.

Nonetheless Moscow has in recent years been seeking to unlock new energy markets in Asia, and now faces a fresh confrontation with the West over Ukraine.

Russian reports cited Alexei Miller, the chief of Russia's energy giant Gazprom, as saying the gas deal was worth $400 billion over its full term.

No confirmation was immediately available on the pricing of the deal.

Under the 30-year contract between CNPC and Gazprom, 38 billion cubic meters could eventually be sent annually from Russia to China, the CNPC statement said.

But the amount is just over half the 70 billion cubic meters envisaged under a 2009 framework agreement between the two.

"This is a big deal that has been over a decade in the making," Raffaello Pantucci, senior research fellow at the Royal United Services Institute for Defence and Security Studies, told AFP.

"The Russians in particular wanted to walk away from these meetings in China, highlighting that they have lots of other substantial options on the table in the face of tensions with the West over Ukraine," he said.

"Putin gets a big win and can go back home showing that he has also managed to finally conclude a discussion that had been going on for over a decade," he added.

Two agreements are involved, one between the companies and one between the governments.

Moscow's relations with the United States and European Union have dived to a post-Cold War low in recent months over Russia's seizure of Crimea and Western accusations the Kremlin is fomenting unrest in the east of Ukraine.

The West has slapped sanctions on some of Putin's closest allies and threatened broader punitive measures if Moscow disrupts presidential polls in Ukraine on May 25.

At the same time, Russia and China, both veto-wielding members of the United Nations Security Council, have sought to strengthen their ties and have often worked in lockstep to contain Washington in recent years.

Xi made Russia his first foreign destination after taking office last year and attended the Sochi Winter Olympics in March.