An investigation of alleged war crimes by the US and others in the Afghan conflict can go ahead, the International Criminal Court (ICC) has ruled.
The ICC overturned on appeal a previous decision to block the investigation.
The actions of the Taliban, the Afghan government and US troops since May 2003 are expected to be examined.
But US Secretary of State Mike Pompeo said the ruling was "reckless" and vowed to protect Americans from it.
"This is a truly breathtaking action by an unaccountable, political institution masquerading as a legal body", he said.
"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 deal was signed with the Taliban last Saturday after more than 18 years of conflict.
The US is not a signatory of the ICC and does not recognise its authority over American citizens.
Last year the Trump administration imposed travel restrictions and other sanctions on ICC officials.
President Donald Trump has also pardoned troops prosecuted in the US for alleged war crimes in Afghanistan.
Afghanistan is a member of the court but officials there have also expressed opposition to the inquiry.
In April 2019 a pre-trial chamber at the ICC ruled that the investigation should not go ahead because it would not "serve the interests of justice".
ICC Chief Prosecutor Fatou Bensouda has been seeking a formal investigation into the alleged crimes since 2017.
An important moment
The International Criminal Court has long been criticised for spending far too much of its time looking at the alleged crimes of smaller - often African - nations and shying away from taking cases involving major world players.
So to this extent its investigation into alleged war crimes in Afghanistan is an important moment.
Its remit is to look at the behaviour of the Taliban, the Afghan Government's forces and of course the Americans.
And therein lies the problem. The United States is not a party to the ICC and is unlikely to co-operate with it. More generally Afghanistan is still far from being at peace.
There will be those who see some kind of judicial process to hold wrong-doers to account as being an essential part of reconciliation in the country. But the practical problems facing any ICC mission may be insurmountable.
What did the court say?
Presiding appeals judge Piotr Hofmanski said the original pre-trial judges had made a mistake.
They had said that an investigation would not be in the interests of justice because it was unlikely to result in successful prosecutions.
But Judge Hofmanski ruled that they had exceeded their powers.
He said that Ms Bensouda's request did meet the criteria, by showing there was a reasonable basis to believe crimes that fall within the court's jurisdiction may have been committed.
What are the allegations?
A preliminary investigation lasting more than a decade examined crimes including intentional attacks against civilians, imprisonment and extra-judicial executions.
A 2016 report from the ICC said there was a reasonable basis to believe the US military had committed torture at secret detention sites operated by the CIA.
The report also said it was reasonable to believe the Afghan government had tortured prisoners and the Taliban had committed war crimes such as the mass killing of civilians.