The European Union's highest court has ruled that Poland's lowering of the retirement age for its supreme court judges was against EU law.
The decision is a blow to the Polish eurosceptic government.
Poland's ruling Law and Justice (PiS) party pushed through the change last year under judicial reforms.
The European Commission said the reforms threatened the rule of law by increasing government control over the courts.
"The Polish legislation concerning the lowering of the retirement age of judges of the Supreme Court is contrary to EU law," the European Court of Justice said in its ruling.
"The measures at issue breach the principles of their removability of judges and judicial independence."
The PiS has originally argued that the changes were needed to improve the efficiency of the courts and rid the country of residues of the Communist era in the judiciary.
As an interim measure, the ECJ last December ordered Poland to suspend the law lowering the age of retirement.
In response the PiS amended the law to remove the obligation to retire judges already in office last year.
But Polish President Andrzej Duda, the author of the law on early retirement, insisted that there was nothing wrong with it and that the European Commission had exceeded its mandate.
The Commission therefore refused to withdraw the case from the ECJ.