Social media companies in Germany face fines of up to 50m euros ($ 57.1; £43.9m) if they fail to remove “obviously illegal” content in time.
From October, Facebook, YouTube, and other sites with more than two million users in Germany must take down posts containing hate speech or other criminal material within 24 hours.
Content that is not obviously unlawful must be assessed within seven days.
The new law is one of the toughest of its kind in the world.
Failure to comply will result in a 5m euro penalty, which could rise to 50m euros depending on the severity of the offence.
In a statement, Facebook said it shared the goal of the German government to fight hate speech.
It added: “We believe the best solutions will be found when government, civil society and industry work together and that this law as it stands now will not improve efforts to tackle this important societal problem.”
German MPs voted in favour of the Netzwerkdurchsetzungsgesetz (NetzDG) law after months of deliberation, on the last legislative day before the Bundestag’s summer break.
But it has already been condemned by human rights groups and industry representatives.
They claim the tight time limits are unrealistic, and will lead to accidental censorship as technology companies err on the side of caution and delete ambiguous posts to avoid paying penalties.
The law will not come into force until after the German federal elections, which will be held in September.
Justice Minister Heiko Maas singled out Facebook, which has some 30 million users in Germany, saying experience had shown that without political pressure, “the large platform operators would not fulfil their obligations” to take down illegal content.
He added that while the law “does not solve all problems”, it tackles the issue of hate crimes on social media, which are “increasingly a problem in many countries”.
Mr Maas, who oversaw the legislation, told the German parliament that online hate crimes had increased by almost 300% in the past few years, adding that “no one should be above the law”.
The bill was drafted after several high-profile incidents of fake news and criminal hate speech being spread on social media sites in Germany.
One case involved the targeting of prominent Green MP Renate Kunast, with a post that falsely suggested she was sympathetic to a refugee who had murdered a German student in the southern city of Freiburg.
For its part, Facebook said it had already made “substantial progress” in removing illegal content, and called into question the efficacy of the law.
The company recently announced it had hired an extra 3,000 staff (on top of the 4,500 it already has) to help monitor “the millions of reports” that come through every week.
Social media companies also point to a recent report by the European Commission, which showed that some 80% of all reported illegal content is already removed in Germany.
In addition to social media sites themselves, three voluntary, independent bodies currently monitor the German internet.
The BBC was given access to one of them, run by Eco, the German Association of the Internet Industry, in Cologne.
In a small, heavily secured office, three legal experts sifted through thousands of complaints from members of the public.
One example shown to the BBC was of a YouTube video titled “Sieg Heil”, a phrase that can be illegal in Germany.
The video was reported to the local police in North-Rhine Westphalia, and followed up with the social network itself after a few days.
But the organisers of the facility, which has been in existence for 15 years, are also concerned about NetzDG, which they say has been “rushed through” for political expediency.
“It takes time to define if a complaint’s content is really illegal or not,” said Alexander Rabe, a member of the Eco board, which was consulted by the government on the draft law.
Mr Rabe also pointed out that much of what many might deem to be “fake news” or hate speech on their social media feeds was not in fact illegal content under current German law.
The bill has also faced criticism from human right’s campaigners.
“Many of the violations covered by the bill are highly dependent on context, context which platforms are in no position to assess,” wrote the UN Special Rapporteur to the High Commissioner for Human Rights, David Kaye.
He added that “the obligations placed upon private companies to regulate and take down content raises concern with respect to freedom of expression”.
The law could still be stopped in Brussels, where campaigners have claimed it breaches EU laws.