Facebook chief executive Mark Zuckerberg. Under a new measure, which cleared Germany's Parliament Friday, companies such as Facebook, Twitter and Google could be fined up to $57 million if they don't delete hateful content. (Noah Berger/AP)

BERLIN — Social-media companies will face stiff penalties under a new German law for failing to swiftly remove hateful content.

The measure, which cleared Germany’s Parliament on Friday, stipulates fines of up to $57 million if companies such as Facebook, Twitter and Google do not delete posts containing racist, defamatory or otherwise illegal speech within 24 hours. The measure is seen as a test case in the battle against fake news and online hate, problems bedeviling governments across the West. But Germany's muscular approach has human rights groups worried about a chilling effect on free expression.

“This law does not solve all problems, but it is an important step in the fight against hate crimes and punishable fake news in social networks,” said Germany’s justice minister, Heiko Maas. “Our experiences have clearly shown that without political pressures, the social networks will not change.”

Germany has staked out a stance that's among the most vigorous in the world against spurious posts and comments on social media. It also has some of the strictest laws regulating forms of expression seen as encouraging violence. Denying the Holocaust and stirring hatred against minorities are punishable with prison time.

In the past two years, Maas said, hate crimes in Germany increased by more than 300 percent. Now, German officials are cracking down on the shadowy online networks they believe incite this activity.

Under the new measure, which takes effect in October, companies have 24 hours to erase illegal content after it is flagged. They have another seven days to sift through messages marked as offensive but not necessarily criminal under German statute. Fines for consistently failing to respond begin at 5 million euros, about $5.7 million, but may go as high as 50 million euros.

Facebook, which recently expanded the number of employees charged with reviewing flagged content, criticized the legislation in a statement, saying it “will not improve efforts to tackle this important societal problem.”

If successful, the law could become a model elsewhere. That has international digital freedom groups worried. A Brussels-based organization, European Digital Rights, warned that the law “could seriously impair human rights online,” assailing the European Union for not intervening to challenge it.

Meanwhile, in Germany, there was a chorus of opposition. Renate Künast, leader of the Green Party, which abstained, said in debate that she feared the “incentive to delete” would crush free speech. The Left Party opposed the measure, as did the far-right Alternative for Germany, which said it might take the matter to court.