In reaction to that traumatic period, the administrations of reformist presidents like Fidel Ramos in the 1990s and Benigno Aquino III a few years ago worked with civil society groups to professionalize the armed forces, reforming military education to emphasize loyalty to democratic values and basing promotions on merit rather than personal connections. As a result, the military has gradually become far less political.

This change is a challenge for Mr. Duterte. In his first year in office, the president has sought to win over the military by offering its personnel higher salaries, more benefits and better equipment. But these promises will be difficult to keep, partly because of constitutional and budget constraints on defense spending.

Even if they are fulfilled, they are unlikely to compensate for the fact that the president and the military seem to be at odds over sensitive security issues.

In February, in the midst of peace negotiations with communist insurgents, Mr. Duterte half-jokingly warned that they shouldn’t press him too hard for concessions, because then the military might “oust me.” For several decades during the Cold War, communists hoped to bring about a Leninist-Maoist system in the Philippines; they have now shrunk to a force of a few thousand rebels, scattered across forests and poverty-stricken rural areas. Some leaders want a peace deal in exchange for immunity, the release of prisoners or certain political reforms, but they are divided about how to move forward.

While he was mayor of Davao City, Mr. Duterte — himself a former student of the communist ideologue Jose Maria Sison and a self-described “socialist” — struck deals with communists who had been occupying parts of the city. Since becoming president, hoping for a nationwide deal, he has ordered the release from prison of some leading communist insurgents and has invited politicians with communist leanings to join his cabinet.

After decades of counterinsurgency campaigns, however, the military brass continues to treat communist rebels and their sympathizers with suspicion. Whenever peace talks have broken down, the army has promptly resumed all-out fighting against them.