WARSAW (Reuters) - Thousands of people staged protests across Poland on Thursday after President Andrzej Duda signed into law a measure effectively letting the government choose the next Supreme Court chief.

Slideshow ( 12 images )

The European Union, human rights groups and opposition parties in Poland say the legislation and other changes pushed by the ruling Law and Justice (PiS) party undermine judicial independence and democracy.

Crowds gathered outside the presidential palace in Warsaw chanting: “Shame.” Many held candles and pens, referring to Duda’s readiness to sign. They shouted: “Break the pen” and “You will go to prison.”

A Reuters witness said scuffles broke out with police after demonstrators wrote slogans on the pavement in front of the presidential palace and that pepper spray was used.

“Someone in the crowd used gas against police officers,” said a spokesman for the Warsaw police, Sylwester Marczak. “Due to the threat, one of the policemen also used a hand-held gas device.”

Protests took place in more than two dozen cities and towns across Poland.

The PiS party has said an overhaul is needed to make the courts more efficient and eradicate the influence of Poland’s communist past.

“Without (judiciary) reforms, we cannot rebuild the Polish state so that it serves its citizens,” said Jaroslaw Kaczynski, leader of the eurosceptic party that combines left-leaning economics with nationalist politics.

Earlier this month, 22 Supreme Court judges were forced into early retirement, but chief judge Malgorzata Gersdorf has refused to go, saying her constitutional term does not expire until 2020.

The latest amendment, which was adopted by the upper house of parliament earlier this week, is designed to make it easier to name the new Supreme Court head.

Since PiS won power in 2015, dozens of judges have been effectively dismissed from the Constitutional Tribunal, the National Judiciary Council, which decides judicial appointments, and now the Supreme Court.

New appointments have used procedures that give parliament, where the PiS has a majority, greater say over the courts and the government more control over judges.

The European Commission is running an unprecedented “rule-of-law investigation” that could lead to the suspension of Poland’s voting rights in the 28-member bloc. It has also opened several separate legal cases against Poland, the largest former communist EU state, including some over the Supreme Court.