Given Mr. Abe’s nationalist leanings, he might not have seemed the most likely Japanese leader to embrace the United States, or a Democrat like Mr. Obama, so warmly.

Yet since he took office four years ago, after an earlier stint as prime minister in 2006-7, Mr. Abe has committed Japan to several policies favored by the Obama administration.

Mr. Abe expanded Japan’s support of United States military bases despite fierce opposition in Okinawa, and pushed through controversial security legislation that allows Japan’s military, the Self Defense Forces, to participate in combat missions abroad. He offered nonmilitary aid to countries battling the Islamic State, even as ISIS militants killed a Japanese hostage.

The clearest motivation for Mr. Abe was the need for a partner in defending against a rising China.

“In the regional geopolitics, I think Japan and the U.S. are both pushed closer to each other by China,” Mr. Ito said. “For security, there is no one but the U.S. which can provide the security to Japan, so there is no question about it.”

Mr. Obama provided very clear promises of protection. In 2014, during a visit to Tokyo, he declared that a security treaty obligated the United States to defend Japan in its confrontation with China over a set of disputed islands in the East China Sea, known in Japan as the Senkaku and in China as the Diaoyu. It was the first time an American president had explicitly said so.

Now Japan’s leaders are warily watching Mr. Trump’s approach to China. They may like that Mr. Trump is taking a more aggressive stance toward Beijing on issues like trade, Taiwan and the South China Sea, but there are also risks for Japan if that stance triggers a hostile response.