TOKYO — The first time Shinzo Abe, Japan’s prime minister, met President Xi Jinping of China, the body language told the story. Mr. Xi looked dour and stiff, turning away from Mr. Abe with pursed lips, as if someone had forced him into it after months of escalating tensions between their two nations. In the years since, relations have improved but the two leaders have always kept at a distance.

This past weekend, they met again on the sidelines of a regional summit meeting in Vietnam. This time, they shook hands and Mr. Xi flashed a grin.

It was a sign, the Japanese news media suggested, of a potentially momentous shift in the region, with two longtime adversaries drawing closer as the United States under President Trump has created unease among allies about the role the United States will take in the region.

To compensate, Japan and China are inching toward a possible reconciliation as they recognize the altered dynamics around the Pacific Rim.