Thousands of anti-government protesters gather in front of the presidential palace in Warsaw | Janek Skarzynski/AFP via Getty Images Thousands protest as Poland tightens control over Supreme Court A controversial new law allows the ruling party to pick next top judicial official.

Thousands took to the streets in Poland Thursday to protest a new law that will allow the ruling right-wing Law and Justice (PiS) party to effectively take control of the country's Supreme Court.

Gathering in front of the presidential palace in Warsaw and in dozens of other cities and towns across the country, crowds chanted "shame" and "free courts!" and sang the national anthem. Police in Warsaw intervened with pepper spray after protesters wrote slogans on the pavement outside the palace, Reuters reported.

The new law signed by Polish President Andrzej Duda will allow the government to choose the next Supreme Court chief, and follows the removal of 22 Supreme Court judges earlier this month. The ruling party has also targeted the Constitutional Tribunal and the National Judiciary Council for dismissals since it came to power in 2015.

Poland's judicial reforms have sparked a fight over the rule of law between Brussels and Warsaw. Following repeated warnings its planned reforms risked falling foul of EU standards, the European Commission in December invoked disciplinary measures under Article 7 of the EU treaties, which theoretically could lead to the suspension of Poland’s voting rights in the European Council.

The ruling party maintains that the legislative changes render Polish courts more efficient. “Without [judiciary] reforms, we cannot rebuild the Polish state so that it serves its citizens,” PiS leader Jarosław Kaczyński said.

Poland's legal system was dealt a blow earlier this week, when the EU's highest court ruled that Ireland could refused to hand over an alleged drug dealer to Poland if its judiciary determines he would not receive a fair trial there. If Irish courts go ahead and block the European Arrest Warrant, they will in effect be deciding that Poland’s judiciary no long functions as a normal part of the EU’s justice system — dealing a blow to Poland’s ruling Law and Justice party.