U.S. President Donald Trump speaks before signing an executive order aimed at requiring hospitals to be more transparent about prices before charging patients for healthcare services, at the White House in Washington, U.S. June 24, 2019.

President Donald Trump on Wednesday questioned the fairness of the United States' longstanding defense pact with Japan just hours before heading to the country for the G-20 summit of world leaders.

The defense agreement, signed in the wake of World War II, is an element of the world order built over the latter half of the 20th century. It requires the United States to come to the defense of Japan in case the island nation is attacked, and allows the U.S. to station troops at military bases there.

"If Japan is attacked, we will fight World War III. We will go in and protect them with our lives and with our treasure," Trump said during an interview on Fox Business Network. "We will fight at all costs, right? But if we are attacked, Japan doesn't have to help us at all. They can watch on a Sony television the attack. So, there's a little difference, OK?"

Trump had privately mused about withdrawing from the defense agreement, Bloomberg News reported this week, though he did not go as far as threatening to scrap the treaty on Wednesday. Pulling out of the treaty would have global implications and would likely reduce U.S. influence in Asia.

According to George Packard, former dean of the Johns Hopkins School of Advanced International Studies, the treaty is the longest lasting alliance between great powers since the 1648 Peace of Westphalia.

Trump's comments are in line with his "America First" foreign policy vision, which generally views international obligations with skepticism. Ahead of his comments on Japan, Trump offered what he called a "general statement."

"Almost all countries in this world take tremendous advantage of the United States. It's unbelievable," he said.

The Japanese Embassy in Washington did not immediately respond to a request for comment. On Tuesday, the country's chief cabinet secretary, Yoshihide Suga, told Bloomberg that the two countries were not discussing a review of the U.S.-Japan security alliance.

On Tuesday, the commander of U.S. Forces Japan, Lt. Gen. Kevin Schneider, met with Japan's minister of foreign affairs, Taro Kono, according to Japan's foreign ministry.