Thousands protested outside the legislature after a full night of debate by sleepy parliamentarians and unsuccessful efforts.
Thousands protested outside the legislature after a full night of debate by sleepy parliamentarians and unsuccessful efforts by Japan's weak opposition to block the law's passage.
The government said the law, which criminalises the planning of serious offenses, is necessary to prevent terrorism ahead of the Tokyo 2020 Olympics.
It doesn't give police new powers, but critics say the legislation could be abused to allow wiretapping of innocent citizens and threaten privacy and freedom of expression guarantees in the constitution.
Terrorism "won't disappear because of this law," said 29-year-old demonstrator Yohei Sakano outside parliament.
"It's mostly designed to crack down on citizens' movements, not terrorism."
Retired government worker Toshiaki Noguchi added: "We're turning into a society of censorship."
US surveillance whistleblower Edward Snowden and Joseph Cannataci, UN special rapporteur on the right to privacy, have both criticised the law, and polls show the public is divided on its merits.
The bill's passage overcame a no-confidence motion against Prime Minister Shinzo Abe's cabinet and a censure bid aimed at Justice Minister Katsutoshi Kaneda.
Tokyo insists the law -- which calls for a prison term of up to five years for planning serious crimes -- is a prerequisite for implementing a UN treaty against transnational organised crime which Japan signed in 2000.
"We will uphold the law in an appropriate and effective way to protect people's lives," Abe told reporters after the legislation passed.
"Three years ahead of the Tokyo Olympic and Paralympic Games, we hope to cooperate with the international community to prevent terror," he added.
The bill was revised several times over the years as earlier versions met with fierce resistance and never made it through parliament.
The latest version reduced the number of targeted crimes to around 270 offences and narrowed the definition of terrorist and criminal organisations. Earlier versions encompassed more than 600 crimes, many unrelated to terrorism or crime syndicates.
The opposition has warned that petty crimes could fall under the scope of the law, and mocked Japan's justice minister when he earlier conceded that, hypothetically, mushroom hunting could be targeted if the fungi were stolen to raise money to fund terrorism.
But even the slimmed-down legislation gives police and investigators too much leeway, some said.
"What comes next will probably be legislation allowing police to wiretap and eavesdrop on telephone and every day conversations," said Setsu Kobayashi, a constitutional expert and professor emeritus at Keio University.
Japanese police have relatively limited access to wiretapping.
"The law makes it possible for authorities to investigate even before a crime has been committed," said Hisako Tsuruta, 63, at a protest outside parliament Thursday afternoon.
"The activities of civil society and labour groups could come under surveillance."
The opposition chastised Abe for trying to push the law through quickly, as he faces mounting criticism over allegations that he gave friends special consideration in a couple of unrelated business deals.
"This is an ultimate form of forced vote -- it shut down sensible debate," Renho, head of the leading opposition Democratic Party who goes by one name, told reporters.
Some Japanese media have likened the bill to the World War II-era "public order maintenance law" under which ordinary people were arrested for political offences, exercising labour rights and anti-war activities.