Spain has narrowly voted in an anti-protest law, which the government argues will ensure public security but opponents say will restrict civil liberties.

The law, which has been called the ‘gag law’ by opposition groups and the media, was passed in the lower house of parliament on Thursday by 181 votes for to 141 against.

It was opposed by all parliamentary groups except the ruling PP party, but it will now go to the Spanish senate where the PP has an overwhelming majority.

READ MORE: Dozens of Spanish cities march in protest against monarchy (PHOTOS, VIDEO)

Spain’s major opposition party, the socialist PSOE, who fought tooth and nail against the bill, have vowed to overturn it if they win the general election in late 2015.

The vote was met with a barrage of ironic criticism from MPs and protesters. The Solfonica Choir – an important part of Spain’s protest movement - started up with “Do you hear the people sing” from Les Miserable musical.While seven MPs from the left wing IU party were asked twice to remove gags from their mouths before the vote could take place.

The Citizens Security Law gives sweeping powers to the authorities. Any unauthorized protests outside buildings that provide basic services to the community will incur a fine of up to €600,000 ($746,000). This covers a huge number of buildings from universities to hospitals.

There will also be a €600 fine for showing a lack of respect to anyone in uniform, while the photographing or filming of police officers, where they could be put in danger, will incur a €30,000 fine.

Migrants are also going to take a hit. Spanish authorities will instantly be able to deport immigrants trying to cross the border into the Spanish North African enclaves in Cueta and Melilla.

READ MORE: 'No more cuts!' Thousands across Spain stage anti-govt protests (VIDEO, PHOTOS)

This measure has been criticized by the international community in recent months because it breaks both international and EU laws.

Spain has seen a growing number of strikes and demonstrations against the massively unpopular austerity program put in place by Prime Minister Mariano Rajoy, although most of them were peaceful.

Opponents also say that it will take Spain back to the 1970s when it was under Franco’s right-wing dictatorship.