BEIJING — It has been eight years since China overtook Japan as the world’s second-largest economy. Yet the Japanese government continued to provide China with development assistance usually reserved for poorer countries. Until now.

In Beijing for the first official visit by a Japanese leader since 2011, Prime Minister Shinzo Abe acknowledged China’s economic dominance by announcing an end to the aid. Instead, he pledged to forge deeper economic and political cooperation, in what is widely seen as a hedge against the volatile, America-first policies of President Trump.

The announcement — coupled with new cooperation agreements Mr. Abe signed on Friday with his Chinese counterpart, Li Keqiang — signaled a significant shift in a relationship that has been haunted by war and occupation and is still strained by territorial disputes and other issues, which, publicly at least, have receded into the background.

The subtext to the budding détente was Mr. Trump, whose go-it-alone approach to foreign relations has pushed the two historic rivals closer together.