With xenophobia rising in South Africa, Home Affairs Minister Aaron Motsoaledi has announced plans to toughen asylum and immigration laws in a move that will have far-reaching consequences for foreign nationals who seek refuge in the country.
His proposals are contained in a document, known as a White Paper, which has been released for public discussion as the first step towards adopting legislation that will mark a decisive break with the more embracing policy that the government - led by the African National Congress (ANC) - championed after it took power at the end of the racist system of apartheid in 1994.
In a sign of the extent to which he envisages changes, Dr Motsoaledi said the government had made a "serious mistake" about two years later when it signed up to international agreements - such as the UN's refugee convention - without seeking exemptions from certain clauses.
This was unlike many other countries, which opted out of clauses giving asylum-seekers and refugees the same rights as their citizens - including the right to employment and education for their children, he said.
Paddy Harper, a journalist with South Africa's Mail & Guardian newspaper, said Dr Motsoaledi's proposals were the latest sign that the government believed it went too far after white-minority rule ended.
"South Africa had been a pariah during apartheid, and as the ANC led its integration into the world it opened up the country to immigrants and asylum-seekers, with many coming from other parts of Africa and Asia," Harper told the BBC.
"The ANC government also did this in the interest of pan-African and international solidarity because of the support it received from other countries during the struggle against apartheid," he said.
"The political and economic dynamics have changed considerably since then, which explains the shift in government thinking."
Dr Motsoaledi is also pushing for people to seek asylum in the first safe country they enter, meaning they could be denied asylum if they came via other countries.
His proposal would mostly affect those from other African nations, as they form the bulk of refugees and asylum-seekers fleeing conflict and persecution.
According to the UN, about 250,000 refugees and asylum seekers live in South Africa. These are separate from documented or undocumented foreign nationals in the country for other reasons, including better economic opportunities.
In a paper published in 2021, an academic at South Africa's University of the Free State, Khangelani Moyo, said that 25% of the refugees and asylum seekers came from Ethiopia, 23% from the Democratic of Republic of Congo, 11% from Somalia, 10% from Bangladesh and 6% from Zimbabwe.
Harper says the number of refugees and asylum-seekers may be small but it feeds into deeper hostility towards foreigners whose population has increased over the last three decades, while South Africa's unemployment rate has soared to around 32%.
"Immigrants - especially Somalis and Bangladeshis - are seen to be controlling the economy of townships, and are accused of taking the jobs of locals. It has led to attacks on migrants, and the emergence of anti-migrant groups, like Operation Dudula," he said.
With this in mind, Harper says that Dr Motsoaledi was looking to next year's elections when he unveiled his proposals.
"Some of the opposition parties are likely to make migration a major campaign issue. The ANC fears losing support, and wants to be seen to be doing something about it, " he said, adding that the governing party's focus on migration also helps deflect attention from its own failures in improving the economy and public services.
In June, senior ANC official Fikile Mbalula described undocumented immigrants as a "ticking timebomb" for South Africa.
"Illegal immigrants put a heavy strain on the fiscus, with adverse effects on service delivery, the overstretched health sector, high unemployment and poverty," he said.
South Africa's latest census recorded more than 2.4 million migrants last year, with the highest percentage coming from neighbouring Zimbabwe at 45.5%, followed by Mozambique and Lesotho.
They make up only around 3% of the total population of 62 million - though officials acknowledge the difficulty in counting foreign nationals, especially those who are undocumented.
For Dr Mosoaledi, it is clear "no-one can account for all undocumented migrants" in South Africa and says the government was already trying to deal with them.
"Immigration Services deport between 15, 000 and 20,000 illegal foreigners every year at a huge cost. This number is on the increase," he said, pointing out that the government was setting up a new law enforcement agency - known as the Border Management Authority (BMA) - to "significantly reduce the risk of foreigners entering the country illegally".
"New legislation must be introduced to strengthen the powers of immigration officers and inspectorate, and make continuing training compulsory," Dr Motsoaledi added.
He also called for the establishment of immigration courts, saying "the current legislative framework was untenable and leads to long delays in finalising immigration matters, including deportation".
Dr Moyo told the BBC that it was difficult to clamp down on undocumented migrants, as most were from neighbouring states.
"If you arrest and deport them, they come back the following week," he said.
"You can't stop the movement of people. It's better to create a mechanism to allow people to be documented."
Yet, with an election looming, the government is unlikely to drop its plans, especially as some opinion polls suggest that the ANC risks losing its outright majority in parliament for the first time since 1994.
As Dr Moyo noted, those parties that called for tougher immigration policies, including tighter border controls, performed "very well" in the 2021 local elections in South Africa's economic heartland of Johannesburg and the capital, Tshwane.