South Africa's Supreme Court on Tuesday rejected an appeal by the government against a ruling that the state had made an error in letting Sudanese President Omar Hassan al-Bashir leave the country despite a court order barring him from doing so.

Bashir, who was in South Africa for an African Union summit last June, was allowed to go even though the court had issued an order banning him from leaving until the end of a hearing on whether he should be detained under a global arrest warrant.

The court said he should have been arrested to face genocide charges at the International Criminal Court (ICC) because as an ICC signatory, Pretoria is obliged to implement arrest warrants.

The ICC has issued a warrant for Bashir on charges of masterminding genocide in Sudan's Darfur region. Bashir denies the charges.

The government had asked the court to overturn the ruling, with its lawyers arguing that a gazette notice granted diplomatic immunity to all delegates at the summit.

In its ruling, the Supreme Court said the government's failure to arrest Bashir "was inconsistent with South Africa's obligations in terms of the Rome Statute...and unlawful".

A rights group that had demanded the arrest of Bashir argued during the appeal that South Africa could not grant immunity to someone wanted for war crimes and crimes against humanity.

"South Africa should not be treated as a safe haven for suspected perpetrators of egregious crimes," Kaajal Ramjathan-Keogh, executive director of the Southern Africa Litigation Centre, which took the government to court, said in a statement.

Justice department spokesman Mthunzi Mhaga said the government was studying the ruling and had not yet decided whether it would challenge it at the constitutional court, the highest court in the land.

The ruling means that Bashir and others facing global arrest warrants for crimes against humanity would be arrested if they set foot in South Africa. In addition, the High Court had said previously that the National Prosecuting Authority should consider whether to take action against the government for letting Bashir leave the country.

In the aftermath of the initial court ruling, the governing African National Congress party said South Africa should withdraw from the ICC, which African states have accused of bias against the continent. Judges at the ICC have also asked South African authorities to explain why they failed to arrest Bashir.