The next day, a new law requiring social media companies to swiftly remove comments flagged as hateful, or face fines of up to 50 million euros, or $57 million, came into effect.

Twitter immediately took down the post, and suspended Ms. von Storch’s account for 12 hours. Ms. von Storch then posted on her Facebook page an image of Twitter’s message informing her of its actions. In the caption, she wished her more than 83,500 followers a “Happy New Year in a free country in which everyone can call barbarians barbarians, even if they are Muslims!”

Facebook later removed that post, Ms. von Storch told her followers. She vowed not to be silenced by the new law, but to continue to “call out problems by name.” She went on to insist that the young men who had sexually harassed German women were “not Protestant Swedes, not Catholic Poles, not Orthodox Russians, not Jewish Israelis and not Buddhist Thais. The overwhelming majority of them are young Muslim men for whom women and followers of other faiths are second-class citizens.”

Ms. von Storch, 46, was a member of the European Parliament until October, when she resigned after her election to the German Parliament. Her comments were particularly provocative because Cologne was the site of a rampage on New Year’s Eve 2015, in which hundreds of men groped, assaulted, harassed or robbed women. Many of the men were asylum-seekers or other immigrants, and the attacks on women fueled criticism by the Alternative for Germany, which argued that Ms. Merkel should not have opened Germany’s doors to so many foreigners.

The party ran on a platform arguing that Islam was incompatible with the German Constitution.

Ulf Willuhn, a spokesman for state prosecutors, said on Tuesday that his office had been alerted to Ms. von Storch’s statement by the Cologne police and was also looking into a statement of support for her, made by a leader of the party, Alice Weidel. As news of the investigation spread, private citizens filed dozens more complaints.