A South African court has ruled that the government's decision to withdraw from the International Criminal Court without parliament's approval was unconstitutional.
A high court judge instructed the government to revoke its notice of withdrawal from the human rights tribunal based in The Hague, Netherlands.
South Africa had been set to become the first country to leave the tribunal that prosecutes the world's worst atrocities.
South Africa's main opposition party had gone to court, saying the government's notice was illegal because parliament was not consulted.
"South Africa does not want to be lumped together with pariah states who have no respect for human rights," the Democratic Alliance said.
A government statement said it would "reflect on the judgment" before deciding whether to appeal.
South Africa's withdrawal announcement last year followed a 2015 dispute over a visit by Sudanese President Omar al-Bashir, who is wanted by the ICC for alleged war crimes, crimes against humanity and genocide in Darfur.
Al-Bashir was allowed to leave South Africa even though a local court ordered authorities to arrest him.
Under the Rome Statute that created the ICC, signatory countries have a legal obligation to arrest anyone sought by the tribunal. South Africa said the treaty contradicts its diplomatic immunity law and prevents the country from acting as a regional peacemaker, a role that could require it to host adversaries on its own soil.
The government said after its notice of withdrawal that a withdrawal bill would go to parliament, where the ruling African National Congress party has a majority.
South Africa notified the United Nations secretary-general that it would withdraw from the treaty that created the ICC, alarming international human rights groups and raising fears of an African exodus from the court, which has more than 120 member states.
Some African countries have argued that the court has unfairly targeted their continent and have instead advocated strengthening their own institutions to deal with threats to human rights.
All but one of the court's full-scale investigations are in Africa, though the majority were referred to the court by the African countries themselves and two by the UN Security Council.
Former UN secretary-general Ban Ki-moon had said he regretted South Africa's decision to withdraw from the ICC and expressed hope that the government would reconsider.
A country's withdrawal becomes effective a year after formally notifying the UN chief. In South Africa's case, that is expected in October.
Backers of the court were dismayed by South Africa's move to withdraw, especially after former president Nelson Mandela had been a strong advocate for the court's creation.
The Democratic Alliance statement echoed concerns that the country under current President Jacob Zuma had drifted far from its ideals.
"This is a victory for the rule of law and indeed for our country's human rights-based foreign policy which Mr Zuma and his cronies have tried so hard to depart from," it said of the court's ruling.