Bleary-eyed Japanese upper-house lawmakers passed the bill on Thursday morning, after a night of stalled efforts to block the legislation in its tracks.

A sizable crowd had assembled the previous day to protest outside parliament.

The bill, which criminalizes the planning of 277 different types of crime, was drawn up by the government, which says it is necessary to prevent terrorism ahead of the 2020 Olympic Games. Ruling politicians also say they need the change to comply with a UN treaty on organized crime.

"We will uphold the law in an appropriate and effective way to protect people's lives," Prime Minister Shinzo Abe told journalists after the legislation was passed.

Japan's more powerful lower house passed the bill last month.

Tokyo struggles with smoking ban ahead of Olympics

Japan to test-drive teleworking ahead of 2020 Olympics

More surveillance powers

The measures would allow a widening of scope for legal wiretapping, with courts more likely to grant police powers for surveillance. The law envisages sentences of up to five years for plotting crimes.

However, the Japan Federation of Bar Associations and several academics say that some of the offenses on the list have nothing to do with terrorism or organized crime.

They include sit-ins to protest against building projects, as well as the copying of copyrighted music.

Mushroom hunting?

Japan's justice minister was even mocked by opponents of the law when he conceded that it could hypothetically target mushroom hunting - if that were used to fund terrorism.

Opposition Democratic Party leader Renho, who goes by only one name, made a statement that deemed the legislation "brutal" and a violation of free thought. He also claimed the bill had been rushed through without sensible debate.

US surveillance whistleblower Edward Snowden has criticized the law, as has Joseph Cannataci, the UN special rapporteur on the right to privacy.

The law in a previous draft was even wider, encompassing some 600 criminal offenses that were seemingly unrelated to crime syndicates or terrorism.

rc/tj (AFP, AP Reuters)