Donald Trump and Japan's Shinzo Abe met on Friday on the sidelines of the G20.

US President Donald Trump on Saturday said he had told Japanese Prime Minister Shinzo Abe that a decades-old security treaty between their countries must be changed, reiterating his criticism of the pact as unfair.

Trump said he was not planning to withdraw from the treaty, which the partners have long called a linchpin of Asia-Pacific stability, but that it placed too great a burden on the United States.

"I told him we'll have to change it," Trump told a news conference after a two-day summit of the Group of 20 major economies in Japan's western city of Osaka.

"I said, look, if someone attacks Japan, we go after them and we are in a battle, full force, in effect," he added. "If somebody should attack the United States, they don't have to do that. That's unfair."

It was not clear exactly when Trump had told Abe this, however. The two met on Friday on the sidelines of the G20, but a senior Japanese government spokesman said no bilateral security issues were discussed.

But the spokesman, Deputy Chief Cabinet Secretary Kotaro Nogami, declined to comment when asked by reporters if Trump had ever mentioned his dissatisfaction with the treaty to Abe in the past. Instead he reiterated the official stance of the two governments.

"In the joint statement issued in February 2017, Prime Minister Abe and President Trump confirmed that the Japan-U.S. alliance based on the security treaty is the foundation of peace, prosperity and freedom in the Asia-Pacific region," he told reporters at a briefing.

"Between the Japanese and U.S. governments, there are no such talks at all about reviewing the security treaty."

The treaty, signed after Japan's surrender in World War Two, commits the United States to defend Japan.

In return, Japan provides military bases that Washington uses to project power deep into Asia, including the biggest concentration of US Marines overseas on Okinawa, and the forward deployment of an aircraft carrier strike group at the Yokosuka naval base near Tokyo.

An end to the security pact is widely seen as raising the risk of forcing Washington to withdraw a major portion of its military forces from Asia at a time when China's military power is growing.