LAGOS, Nigeria — They fled mob attacks and the torching of their stores and arrived with nothing but their children and their suitcases. More than 300 Nigerians landed in Lagos on a flight from Johannesburg late Wednesday because their old lives — as immigrants living in South Africa — had become untenable.

They arrived after dark, descended from the plane and lined up at the door of a yellow transit center, eyes glassy with fatigue. Sign here, officials told them. Wait there. They had little money and almost no plans.

Hatred of foreigners, they said, had long been a problem in South Africa, and it is what finally drove them out.

“If I had stayed,” said Socarvin Onuoha, a Nigerian who owned a cellphone shop for more than a decade, “I would have died.”