Poland's senate on Friday rejected a controversial draft law aimed at punishing judges who question government-backed judicial reforms that the European Union says are out of step with the rule of law.

The upper house, where the opposition holds a narrow majority, voted 51 to 48 to reject the draft, senate speaker Tomasz Grodzki said.

More:

The draft now returns to parliament, where lawmakers from the governing right-wing Law and Justice (PiS) party hold a majority and have vowed to force the measure into law despite the senate's objection.

The PiS government argues that the reform will tackle corruption in the judiciary, but opponents insist it is aimed at gagging critical magistrates and so undermines judicial independence.

Supreme Court president Malgorzata Gersdorf has denounced the draft bill as a "muzzle law".

Since taking office in late 2015, the PiS has introduced a slew of controversial judicial reforms that it insists are designed to tackle corruption in the courts, still haunted by the communist era.

The changes have, however, sparked widespread protest in European legal circles, where concern is mounting that they threaten not only the rule of law in Poland but also, more broadly, the EU's entire legal system.

Judges from nearly all EU member nations joined hundreds of their Polish colleagues in Warsaw last Saturday in an unprecedented street protest against the draft law on disciplining judges.

In late 2017, the EU launched unprecedented proceedings against Poland over "systemic threats" posed by the reforms to the rule of law that could see its EU voting rights suspended.

The European Court of Justice has questioned several of the reforms.

"The non-compliance with EU law in Poland is now having an impact on the functioning of the EU legal order," Laurent Pech, a professor of European law at Middlesex University London, told journalists in Warsaw this week.

"From the EU's point of view, this is a survival matter," he said, adding that Poland would have to repeal all judicial reforms introduced by the PiS since 2015 in order to comply with EU law.

"Otherwise this is the beginning of the end of the EU legal system as such."