South Africa’s high court has temporarily prevented the deportation of more than 300 undocumented migrants.
Rights activists have criticised the arrests of more than 700 suspected illegal migrants following recent deadly xenophobic violence.
Police say they made the arrests during crime prevention operations.
The authorities have been under pressure to both bring an end to the attacks on foreigners and to introduce tighter immigration controls.
The African migrants detained at the Lindela repatriation centre, 25km (15 miles) west of Johannesburg, were due to be deported on Wednesday, reports the BBC’s Nomsa Maseko.
They had been arrested over the past few weeks during night time raids in and around Johannesburg.
But their deportation has been halted for at least two weeks after the organisation Lawyers for Human Rights went to the Johannesburg High Court to prevent it from taking place.
The lawyers have also been given permission to consult with their clients after being barred from doing so by the government.
This will give the lawyers time to get a list of names of those who have been arrested, and check if they are in the country as asylum seekers.
The raids come after a wave of xenophobic attacks in April which affected major cities in South Africa.
At least seven people were killed, 5,000 left homeless and many foreignowned shops were looted in the attacks.
Campaign group Right to Know called the mass arrests of suspected illegal migrants “state-funded xenophobia”.
“The raids were a heavy-handed response that have seen families being separated,” the group’s spokesman Murray Hunter told the AFP news agency.
Steve Faulkner, from the Coalition of Movements Against Xenophobia, described a recent raid on Johannesburg’s Central Methodist Church, where many refugees seek shelter, as a “military operation in the middle of the night… People were herded together and taken to the police station”, AFP reports. South Africa’s President Jacob Zuma has condemned the violence against foreigners and the army was deployed in some areas to prevent further attacks.
But in a speech to mark the anniversary of country’s first democratic elections he also talked about concern around the “number of illegal and undocumented migrants” and promised to do something about it.