In easier times for Egypt’s refugees, Azza Mostafa, a pro-government TV anchor, had nothing but generous words for the many thousands of Syrians who had built new lives in Egypt after their own country imploded into civil war in 2011.

“I’d like to say to our Syrian families and our brothers in Egypt,” she said in a 2019 broadcast, “you’ve truly brought light to Egypt.”

But there she was on her show in June, fulminating against Egypt’s growing number of outsiders — an echo of the country’s leaders, whose policy toward refugees and migrants has hardened as they wrestle with an economic crisis made worse by wars in neighboring Gaza, Sudan and Libya.

“This has become unbearable,” Ms. Mostafa said, accusing migrants of driving up rents and promoting female genital mutilation. “There are many acts of overstepping bounds. Is that acceptable? After we opened our country for them?”

Egypt long made it easy for foreigners of all kinds to live and work in the country, largely without interference, whether they were refugees, migrant workers or Westerners escaping coronavirus lockdowns.

The past 13 years have brought a near unbroken stream of newcomers fleeing conflict to the country that is known among Arabs as the “mother of the world.” That includes not just Syrians but also Sudanese, Yemenis, Eritreans and, most recently, Palestinians from Gaza.