The International Criminal Court (ICC) has rejected its prosecutor's request to investigate alleged war crimes in Afghanistan.
Court judges highlighted instability and the lack of co-operation with investigators in the country.
The ruling was hailed by US President Donald Trump as a "major international victory" but human rights group Amnesty International criticised it.
It comes a week after the US revoked ICC prosecutor Fatou Bensouda's visa.
That was thought to have been in response to her request to investigate possible crimes committed by US forces in Afghanistan.
Explaining their unanimous decision, the three ICC pre-trial chamber judges said such an investigation "would not serve the interests of justice".
Mr Trump said it was a victory "not only for these patriots, but for the rule of law".
In his statement, he called the ICC "illegitimate" and said it would be met with a "swift and vigorous response" if it tried to prosecute citizens of the US or its allies.
Amnesty said the refusal to investigate was a "shocking abandonment of victims" that would "weaken the court's already questionable credibility".
Amnesty's Biraj Patnaik said the decision would be seen as a "craven capitulation to Washington's bullying".
ICC prosecutors have been examining alleged abuses committed by all parties in Afghanistan's long conflict for more than a decade.
A formal examination of potential crimes began in November 2017.
But while the court said there was "a reasonable basis" to believe crimes had occurred, judges said Afghanistan's current situation "make the prospects for a successful investigation and prosecution extremely limited".
They also cited the long period that had passed since the investigation began in 2006, and said the court needed to "use its resources prioritising activities that would have better chances to succeed".
What is the ICC?
The court investigates and brings to justice people responsible for genocide, crimes against humanity and war crimes, intervening when national authorities cannot or will not prosecute.
The ICC was established by a UN treaty in 2002, and has been ratified by 123 countries, including the UK.
However, several countries - including China, India, Russia and the US - have refused to join, while some African countries say the court is unfairly focused on Africans.
Why is the US opposed to it?
US administrations have long criticised the ICC, arguing its soldiers could become the subject of political lawsuits.
President Bill Clinton signed the treaty establishing the court before the end of his term in office, but Congress never ratified it.
While the UN at one point gave US troops immunity - after the country threatened to withdraw its troops from peacekeeping in Bosnia - this exemption was cancelled in June 2004, two months after pictures of US troops abusing Iraqi prisoners shocked the world.
Last September National Security Adviser John Bolton threatened the ICC with sanctions if they pursued cases against US citizens.