"Acts of lawlessness, intimidation and humiliation directed at foreign nationals, whether they are documented or undocumented, should not be tolerated," Ramaphosa told parliament in a televised address.
A new anti-immigration movement dubbed Operation Dudula, meaning "push back" in Zulu, has been picketing Kalafong Hospital in Atteridgeville, a township west of Pretoria.
Protesters have blocked patients on the basis of skin color and language, infringing on basic rights, the government said in a separate statement.
Their actions "go against the tenets of our hard fought for democracy," it said, referring to the struggle against apartheid -- a system that brutally divided the country along the lines of race.
Ramaphosa maintained that South Africans were not "xenophobic" but "quite welcoming."
But he added that law enforcement and security forces were carrying out operations to deal with the issue of illegal migration.
The protestors blame long waits and poor service in the public health sector on strains caused by an influx of foreign migrants.
Their action follows a viral video of provincial health minister Dr Phophi Ramathuba berating a Zimbabwean patient, accusing her of seeking treatment at a government hospital at the expense of South Africans.
Medical care at public hospitals in South Africa is free, but the costs are borne by payroll and other taxes.
The Zimbabwean embassy in Pretoria then issued a statement saying its officials watched "with shock and disbelief" how the patient was treated by the minister.
Hostility towards foreign patients has been "intensifying" since Ramathuba's remarks became public this month, Doctors Without Borders (MSF) said last week.
Around four million foreigners live in South Africa according to official estimates, but the government has no reliable figures as to how many do not have valid papers.
The picket line at the hospital has been filtering people with darker skins -- a tactic seemingly aimed at Zimbabweans, Mozambicans and Nigerians -- and then asking them to speak in a local language or dialect.
The protest group, Operation Dudula, was formed in January.
South Africa has been swept by waves of anti-foreigner sentiment that have led to violent, and at times deadly, attacks on immigrants.
In April, Elvis Nyathi, a 44-year-old Zimbabwean, was burned alive in a township north of Johannesburg, where police said militants went banging on doors demanding to see residents' visas.
In 2008, 62 people were killed in anti-immigrant riots. Other bouts of violence erupted 2015, 2016 and again in 2019.
A major source of anti-foreigner sentiment is South Africa's sickly economy. More than a third of the workforce is jobless, with young people hardest hit.