Japanese Prime Minister Shinzo Abe, left, with U.S. President Donald Trump | Nicholas Kamm/AFP via Getty Images Japan feels the pain of an ally like Trump Trump worries Japan with his hardball trade tactics and friendship with Kim Jong Un.

BIARRITZ, France — Japan handed Donald Trump a big trade win on Sunday, but did so through gritted teeth as the U.S. president pushes the most important strategic alliance in northeast Asia to its limits.

If it weren't enough that Trump bludgeoned his way to Sunday's trade accord by threatening sky-high tariffs on Japanese carmakers, Tokyo is also now wrestling with an American president who takes an alarmingly cavalier view of the U.S.-Japanese military alliance that underpins security on the Korean peninsula.

Only hours before announcing the U.S.-Japan trade deal, Trump had an embarrassingly public falling out with Japan's Prime Minister Shinzō Abe over whether North Korean dictator Kim Jong Un had broken international law with recent missile launches. It was a dialogue that no Japanese leader could have imagined possible over the past seven decades.

Trump said that he is "not happy" about Kim's missile tests, but argued that the North Korean leader was "not in violation" of international law. He then added that he had received a "nice letter" from Kim that he was upset about South Korean military exercises.

Abe promptly shot back: "Our position is very clear that the launch of short-range ballistic missiles by North Korea clearly violates the relevant U.N. Security Council resolutions."

"Trade wars will lead to recession, while trade deals will boost the economy" — Donald Tusk, European Council president

Unimpressed, Trump said that he understands how the Japanese prime minister feels, but played down the significance of short-range tests. "A lot of people are testing those missiles, not just him. A lot of people are testing those missiles. We’re in the world of missiles, folks, whether you like it or not.”

That was hardly music to the ears of the Japanese, who see nuclear-armed North Korea as their key strategic problem, and the U.S. is supposed to be their most loyal ally in combatting the dynasty of the Kims.

“I would like to make sure that we — meaning, myself and President Trump — will always stay on the same page when it comes to North Korea,” Abe said in response to a reporter’s question about whether he would like Trump to move closer toward his position.

While Abe managed to collect himself to hail the trade deal as a "win-win matter" shortly afterward, the pact has also left a bitter taste in Japanese mouths. It is an agreement "in principle" that both parties hope to sign at the U.N. General Assembly next month.

For more than a year, however, Japan and the European Union have joined forces in arguing that Trump was acting illegally by trying to put additional 25 percent duties on their car exports for "reasons of national security."

Last year, Brussels and Tokyo released a joint statement warning that Trump's threatened tariffs would have "a major restrictive impact affecting a very substantial part of global trade."

However, by agreeing to the trade deal, which in principle lowers Japan's high agricultural tariffs in exchange for a reprieve from Trump's auto tariffs, Tokyo risks giving Trump a prime reason to believe that his gun-to-the-head tactics work.

At its heart, the agreement lowers Japanese duties on U.S. farm exports, while the U.S. makes no concession on lowering its existing 2.5 percent tariff on car imports. And Trump lauded the deal precisely as a win for American farmers. He said Japan had agreed to buy "all of that corn" that has been piling up in America after grain exports to China plummeted as a result of the president's trade war with Beijing.

The Japan deal also gives an urgently needed win to Trump, who is facing increasing criticism over the economic damage caused by his trade wars at home.

As a bonus, it also heaps renewed pressure on the EU, which is also in line for Trump's auto duties as early as November.

European Council President Donald Tusk on Saturday issued a renewed appeal to Trump not to threaten the EU with tariffs: "Trade wars will lead to recession, while trade deals will boost the economy, not to mention the fact that trade wars among G7 members will lead to eroding the already weakened trust among us."