A landmark natural gas deal with China offers Russia an alternative to markets in European countries angered by the Kremlin's stance on Ukraine, and highlights growing ties between the former rivals at a time when they are both at odds with Washington.
The 30-year deal signed Wednesday calls for Russia to supply 38 billion cubic meters of gas via a pipeline from Siberia to energy-hungry cities in northeastern China, including Beijing and Tianjin.
Russian President Vladimir Putin, whose country is heavily dependent on energy exports, had eagerly sought the agreement to protect against a reduction or cutoff by big European customers such as Germany, a possible next step in sanctions against Russia in the dispute over Ukraine.
Putin also knows that most of his country's exports to Europe go through pipelines that cross Ukraine, making them subject to retaliation for Russia's seizure of the Crimean peninsula and its suspected backing of pro-Russia separatists in eastern Ukraine.
The Russia-China deal "is a clear signal to the West that Russia has a real alternative," said Andrei Kokoshin, dean of Moscow State University's world politics faculty and a former head of Russia's Security Council.
Senior Russian officials have warned that reaction to the seizure of Crimea and concern over Kremlin policy in Ukraine were cutting into economic growth rates and fueling capital flight from Russia.
Russia has edged away from Ukraine's separatists, declining to endorse the results of referendums on independence they held May 11. Kremlin officials also have refused to recognize the opposition politicians running Ukraine since former President Viktor Yanukovich was ousted, saying they are unelected and therefore illegitimate.
Moscow had also denounced as illegal the election to replace Yanukovich, set for Sunday. But it changed its stance after U.S. and European leaders warned that further economic sanctions would follow if Russia interfered with the vote.
Putin, attending an Asian security summit Wednesday in China, told journalists that he had ordered Russian troops back from the Ukrainian border to "create additional, favorable conditions" for the election.
"Any political process is better than an armed standoff," he said, apparently referring to round-table talks between Kiev's interim leaders and representatives of Ukraine's disparate regions on ways to decentralize power in the nation.
Polls in Ukraine indicate that confection magnate Petro Poroshenko has a commanding lead in the presidential campaign. Russian Foreign Minister Sergei Lavrov said last week that Poroshenko was someone with whom Russia could deal.
Pro-Russia separatists also are under new pressure from a steel and mining magnate who employs 300,000 people in eastern Ukraine. He claimed Wednesday to have mobilized a million protesters against the separatists.
Rinat Akhmetov, Ukraine's richest man, heralded his Voice of Donbass campaign as evidence that most people in the turbulent east oppose the armed disruptions in the Donetsk and Luhansk regions.
Protests organized by Akhmetov and managers of his industrial operations, which are the economic backbone of the Donbass region, have galvanized the peaceful majority "against destabilization of the situation in Donbass, against violence and chaos, banditry and looting," the mogul said in a statement.
The protests began Tuesday with employees called to stand outside their workplaces at noon while factory whistles sounded from dozens of enterprises.
Akhmetov said Wednesday that more than a million workers took part, including 200,000 from his own businesses. The figures could not be independently confirmed. The magnate's enterprises are scattered across a wide swath of eastern Ukraine and are inaccessible to most journalists because of the separatists' roadblocks and railroad disruptions.
The Voice of Donbass campaign demands the disarming of all "illegal insurgent gangs," release of hostages and unblocking of occupied buildings and seized rail and road links to the region.
In Shanghai, Putin and Chinese President Xi Jinping witnessed the signing of the energy deal on the last day of the security summit. The agreement was signed by the heads of the countries' state-owned energy giants, Russia's Gazprom and China National Petroleum Corp.
Before the meeting, Putin extolled Beijing as a most "reliable friend."
"It would not be wrong to say that it [the relationship with China] has reached the highest level in all its centuries-long history," Putin said in an interview with Chinese media.
The gas deal had been in the works since the 1990s, with China holding out until the end for price concessions. Financial terms were not disclosed.
Russia and China also celebrated their friendship with joint maritime exercises in the East China Sea, where China is locked in a dispute with Japan over uninhabited islands. China also is at loggerheads with Vietnam and the Philippines over resource rights in the South China Sea, a situation for which it blames the United States.
"The relationship between China and Russia is definitely at a new stage. Both trust each other. The leaders keep frequent communication," said Yang Chuang, a retired diplomat at China Foreign Affairs University in Beijing.
The friendly relations between the onetime foes come as both are caught in a cycle of deteriorating relations with the United States. The U.S. and China are dueling over accusations that China's military is engaged in Internet hacking of U.S. businesses; Russia has angered the U.S. by embracing secrets leaker Edward Snowden and by intervening in Ukraine.
Putin's visit to Shanghai came almost exactly 25 years after a 1989 trip to Beijing by then-Soviet leader Mikhail S. Gorbachev to seal the reconciliation of the two communist powers. Gorbachev was welcomed as a beacon of liberalization by pro-democracy students who were camped out at Tiananmen Square, just weeks before the brutal crackdown by the Chinese military.
A quarter of a century later, Beijing is under heightened security as the leadership rounds up activists and curtails the Internet to prevent commemorations of the crackdown.
Williams reported from Kiev and Demick from Beijing.