Prime Minister Fumio Kishida of Japan arrived in Kyiv on Tuesday to meet with President Volodymyr Zelensky of Ukraine, becoming the latest leader of the Group of 7 nations to travel to the country as he seeks a more active role for Japan in international affairs.

Russia’s invasion of Ukraine has galvanized Japan’s foreign and military policy, stoking concerns about the costs of geopolitical instability. Policymakers and the public alike worry that the country would be unprepared to handle a crisis in its own backyard, whether North Korean aggression or an attempt by China to take the self-ruled island of Taiwan.

The timing of the visit, which coincided with the second day of meetings between China’s leader, Xi Jinping, and President Vladimir V. Putin of Russia, set the stage for competing displays of support from the East Asian neighbors.

Rahm Emanuel, the U.S. ambassador to Japan, said the prime minister’s show of solidarity with Mr. Zelensky was in contrast to the partnership between Mr. Xi and Mr. Putin, calling the alignment between the Chinese and Russian leaders “nefarious.”

Mr. Xi is visiting Moscow “to protect Vladimir Putin from the International Criminal Court and pardon him from international public opinion against this war,” Emanuel wrote in a statement. “Prime Minister Kishida stands with freedom, and Xi stands with a war criminal,” the ambassador wrote.

A spokesman for China’s Foreign Ministry responded to news of the visit by saying Japan should “help de-escalate the situation instead of the opposite.”

The war has raised concerns about Japan’s reliance on other countries for food and energy, most of which it imports. Prices for commodities such as natural gas jumped after the invasion, putting cost pressures on Japan’s production of electricity. In response, the country has pushed for closer relationships with its allies and broken a decades-long deadlock in military spending as it plans to double its budget over the next five years.

It is a significant change for Japan, where the Constitution limits the country’s ability to engage in military action and the public has long resisted any policies that even hinted at walking back its longstanding official stance of pacifism. The increase raises spending to around 2 percent of annual economic output, aligning Japan with members of NATO. The move is seen as signaling its preparedness to play a more active role in any military crisis in the Asia-Pacific region.

In a further break from past behavior, Japan has drawn a clear line on the war in Ukraine, joining with other G7 nations to impose sanctions on Russia and providing billions of dollars in financial aid, as well as nonlethal military aid, such as helmets and bulletproof vests. Late last month, Mr. Kishida pledged $5.5 billion in additional support.

Mr. Kishida embarked for Ukraine from India, where he had met with Prime Minister Narendra Modi on issues including protecting freedom of navigation in the Pacific.

In a speech on Monday at the Indian Council of World Affairs, a research institute in New Delhi, Mr. Kishida said that Russia’s war had driven a “paradigm shift” in global affairs.

“Russia’s aggression against Ukraine oblige us to face the most fundamental challenge: defending peace,” he said, according to prepared remarks.

Mr. Kishida flew from India to Poland, where he boarded a train to Kyiv, according to NHK, the Japanese public broadcaster. The secretive journey was highly unusual for a prime minister in Japan, where the leader’s movements are typically broadcast well in advance and reported in detail. Japan’s Kyodo News agency reported on Tuesday afternoon that he had arrived in Kyiv.

Hisako Ueno and Victoria Kim contributed reporting.