ST. PETERSBURG, Russia — In back-to-back speeches at an investment conference Friday, the leaders of Russia and China cast themselves as the champions of free markets and global trade, an overt show of opposition to what they portrayed as the United States’ retreat into protectionism with sanctions and tariffs.
President Xi Jinping of China spoke expansively about his country’s firm support for globalization and open borders, saying that “we all must work to bring about a harmonious world.”
In his speech, President Vladimir V. Putin of Russia took a much darker turn, hinting that trade wars could turn into real wars. He argued that the United States, after decades of “pretending” to promote free markets, had been turning its back on them because powerful economic competitors had emerged, threatening America’s dominance.
Together, the two leaders’ remarks highlighted the strengthening ties between Russia and China as their relations with the United States sour.
Western countries, led by the United States, have imposed sanctions on Russia in the wake of election interference, a military incursion in Ukraine and a series of human rights abuses. Since early 2018, the Trump administration has placed tariffs on more than $250 billion worth of Chinese imports and has threatened a further round on roughly $300 billion worth of goods, saying it has engaged in unfair trade practices.
President Trump has often turned to tariffs as a way to shape geopolitics. Unless a last-minute deal is reached, the United States will impose tariffs on all imports from Mexico as a way to curb the flow of migrants crossing the border.
On Friday, Mr. Xi argued that nations must preserve and improve trade rules rather than throw them out over what he suggested were minor irritants.
“If you are unhappy with fleas in your fur coat, you should not throw the fur coat in the oven,” he said, according to an official translation. “The current multilateral trade system has to be protected.”
Certainly, not everyone benefits from a level playing field, Mr. Xi added wryly, arguing in defense of the world’s existing trade rules that allow for low tariffs, once propped up by the United States.
The United States’ trade policy left an opening for two leaders who have previously found themselves on the receiving end of such criticism. China has been roundly accused of stealing intellectual property, and one of its largest technology companies, Huawei, has been facing restrictions around the world. Russia has nationalized energy companies as oil made up an increasingly larger portion of its exports.
The Kremlin heavily promotes the annual investment conference held this week, the St. Petersburg International Economic Forum, as a way to foster foreign investment. The American ambassador, Jon M. Huntsman Jr., boycotted this year’s conference after the arrest of an American banker in February, which sent a chill through Western investor circles.
At the same time, relations between Russia and China have been warming. Mr. Putin has pushed to increase cooperation with Asia over the last five years in the wake of sanctions and other efforts to isolate Russia after its annexation of Crimea and attempt to destabilize Ukraine.
Russia recently released data that showed that trade between Russia and China grew $108 billion last year, almost a 25 percent increase from the year before — a figure buoyed by rising oil prices.
Friday was the final day of Mr. Xi’s three-day visit to Russia. On Wednesday, he said that “President Putin is for me a best friend.” The next day, Mr. Putin took Mr. Xi on a boat tour around the canals of St. Petersburg.
“We hated to leave, as there are so many issues to discuss,” Mr. Putin said of that meeting.
But when he was asked at the conference on Friday if he would take sides in the trade war between the United States and China, Mr. Putin said he was citing a Chinese proverb that “when tigers fight in the valley, the smart monkey sits aside and waits to see who wins.”