TOKYO — President Rodrigo Duterte of the Philippines, on a trip to Japan, said Wednesday that he wanted all foreign troops out of his country within “maybe two years” and that he was willing to revoke base-hosting agreements with the United States.

The remarks, made to a group of Japanese and Filipino businessmen in Tokyo, are the clearest signal yet that Mr. Duterte wants to renegotiate the 2014 agreement his predecessor reached with the United States to let the Pentagon use five Philippine military bases, a central component of the Obama administration’s plan to bolster American influence in Asia.

“I want them out,” Mr. Duterte said of the American troops in his country, adding that he was willing to “revise or abrogate agreements.” He also repeated a recent assertion that he would withdraw from any joint military exercises with the United States, a treaty ally. “This will be the last maneuver, war games, between the United States and the Philippine military,” he said, according to a transcript of his remarks.

Mr. Duterte’s trip to Japan is his first state visit since he said in China last week that he wanted a “separation” from the United States, a remark he later softened. He told his Tokyo audience on Wednesday that he had discussed only economic matters with Chinese officials, not security or alliances.