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.