KABUL — The International Criminal Court ruled that its chief prosecutor can open a wide-ranging investigation of possible war crimes in Afghanistan by the Taliban, Afghan government forces and U.S. troops.

The ruling comes despite strong opposition from the United States, which does not recognize the court’s jurisdiction. Afghanistan has also opposed the investigation but is an ICC member state.

This will be the first investigation opened by the court involving U.S. troops. The ruling comes less than a week after the United States and the Taliban signed a peace deal that calls for the full withdrawal of U.S. forces from Afghanistan within 14 months and for the Taliban to disavow terrorist groups.

Secretary of State Mike Pompeo on Thursday called the ICC’s move “a truly breathtaking action by an unaccountable political institution masquerading as a legal body. It’s all the more reckless for this ruling to come just days after the United States signed a historic peace deal on Afghanistan, which is the best chance for peace in a generation.”

The United States will take all necessary measures “to protect our citizens from this renegade, unlawful so-called court,” he said in a news briefing.

Chief prosecutor Fatou Bensouda requested authorization to investigate possible war crimes in Afghanistan in 2017.

Bensouda said there was reason to believe that members of the U.S. military and intelligence agencies had “committed acts of torture, cruel treatment, outrages upon personal dignity, rape and sexual violence against conflict-related detainees in Afghanistan and other locations, principally in the 2003-2004 period.”

The Trump administration has taken a strong stand against the court’s authority, describing attempted investigations involving U.S. forces as attacks on U.S. sovereignty that would subject Americans to unjust inquiries.

In April, the United States revoked the entry visa of the court’s chief prosecutor, and last year, Pompeo threatened “economic sanctions, if the ICC does not change its course,” referring to the investigation of U.S. forces in Afghanistan.

When the court later decided to abandon the inquiry, President Trump called the decision “a major international victory, not only for these patriots, but for the rule of law.” The ICC said it had decided that the lack of cooperation among the concerned parties made the chances of a successful prosecution remote.

But in Thursday’s ruling, the court said in a statement that it “erred” in that decision and that the court should have considered only “whether there was a reasonable factual basis for the Prosecutor to proceed.”

Rights activists applauded the announcement.

“This is an historic moment where the International Criminal Court has reversed a terrible mistake and decided to stand by the victims of war crimes and crimes against humanity committed by all sides to the conflict in Afghanistan,” Solomon Sacco, Amnesty International’s head of international justice, said in a statement.

Param-Preet Singh, associate international justice director at Human Rights Watch, said the decision “reaffirms the court’s essential role for victims when all other doors to justice are closed.”

Carol Morello in Washington contributed to this report.