CAIRO — Dozens of men with clubs and knives stormed a charity for Syrian refugees a few days after the Egyptian military ousted President Mohamed Morsi — making it clear they were no longer welcome in Egypt.

“You Syrians — you’re setting the country on fire,” the attackers yelled in July as they beat Raqan Abulkheir, who is originally from Homs in central Syria. He runs the refugee center out of an apartment in a Cairo suburb where thousands of Syrians have settled. His 25-year-old son was bludgeoned over the head and left in a coma.

During the two and a half years of civil war in Syria, more than two million people have fled the country, most of them taking up residence as refugees in Jordan, Lebanon and Turkey. But as many as 300,000 have eventually made their way to Egypt, where they were welcomed, including by Mr. Morsi and his Islamist allies, who were vocal backers of the rebellion against President Bashar al-Assad.

“The people here supported us,” said Mohamed Taher, a filmmaker from northern Syria. “Egyptians did what they could to help Syrians. They went out of their way to do more.”