President Vladimir V. Putin attended a trade fair on Friday in a northeastern Chinese city and toured a state-backed university famous for its cutting edge defense research, highlighting how economic and military ties between the countries have grown despite, or perhaps because of, Western pressure.

Mr. Putin’s visit to Harbin, a Chinese city with a Russian past, is part of a trip aimed at demonstrating that he has powerful friends even as his war against Ukraine — a campaign that he is escalating — has isolated him from the West. The visit followed a day of talks between him and President Xi Jinping of China that seemed orchestrated to convey not only the strategic alignment of the two powerful, autocratic leaders against the West, but a personal connection.

State media showed Mr. Putin and Mr. Xi, neck ties off after formal talks on Thursday, strolling under willow trees and sipping tea at a traditional pavilion on the sprawling grounds of Zhongnanhai, the walled leadership compound in Beijing, with only their interpreters. As Mr. Xi saw Mr. Putin off in the evening, he even initiated a hug — a rare expression of affection for the Chinese leader.

“Xi’s very deliberate embrace of Putin for the cameras wasn’t just to emphasize the closeness of the political relationship between the two countries and their leaders,” said Richard McGregor, a senior fellow for East Asia at the Lowy Institute in Sydney. “There was also a touch of disdain directed at Washington, which has been pressuring Beijing to withdraw support from Moscow. That clearly isn’t going to happen in any substantive fashion.”

The show of camaraderie was the final touch in talks that culminated in a joint statement that took aim at the United States, which Mr. Putin and Mr. Xi have accused of seeking to suppress their countries. The statement pledged that Russia and China would work more closely in critical sectors like energy, space and the military.