MANILA — The Philippines said Tuesday it had officially informed the United States that it was scrapping a military pact that has given the longtime American ally a security blanket for the past two decades.

The notice to terminate the pact, the Visiting Forces Agreement, comes as President Rodrigo Duterte has warmed up to China while distancing himself from the United States, the Philippines’ former colonial ruler. The move also comes as the Philippines has shown increasing reluctance to stand up to China over its territorial claims in the South China Sea.

The agreement has let the United States rotate its forces through Philippine military bases. It has allowed for about 300 joint exercises annually between the American and Philippine militaries, said R. Clarke Cooper, the assistant secretary of state for political-military affairs. He told reporters Monday the termination of the agreement would put those operations “at risk.”

The pact still remains in force, but the notice to terminate it, delivered to the American Embassy in Manila, starts a clock under which it will remain in effect for 180 days before lapsing.