The raid late yesterday came hours after Defence Minister Nosiviwe Mapisa-Nqakula said the army was being deployed as a "last resort" to support the police after weeks of unrest that have left at least seven people dead.
As a helicopter hovered overhead, dozens of soldiers surrounded the workers' hostel before police stormed the building.
Officers moved from floor to floor conducting searches as residents lay face down in corridors.
Mobs of South African men in Johannesburg and in the port city of Durban have targeted migrants from Zimbabwe, Malawi, Mozambique and other African countries over the past three weeks.
The government stepped up its response by sending in troops to back the police.
The South African National Defence Force said in a statement that it would "not stand by and watch whilst innocent lives are being threatened".
Immigrants are often the focus of resentment among poor South Africans, who face chronic job shortages with youth unemployment at over 50 per cent.
