The EU's Court of Justice has ruled that Poland's decision to lower judges' retirement ages contravened EU law, in a new setback to the government's bid to reform the judiciary.
Poland has already reversed the 2017 reforms, after an outcry at home as well as in Brussels.
Poland broke EU law on two fronts.
The Court said it was wrong to set a lower retirement age for women and to give a minister a final decision on which judges could stay in a job.
The Polish foreign ministry responded by saying the law had been changed. As the verdict "relates to an old situation" it said the complaint should have been withdrawn.
What happened to the law?
At the time, both male and female judges and prosecutors retired at 67 but Poland's socially conservative government cut the age to 60 for women and 65 for men.
Poland's government, run by the Law and Justice Party (PiS), argued it was trying to fight corruption and replace judges whose careers dated back to the communist era, but critics said it was seeking to appoint loyalists instead.
Some 100 judges were forced to retire before the law was withdrawn.
What the Court has said
The Luxembourg-based court said that under EU law judges and prosecutors were entitled to equal pay and treatment for equal work. It rejected a Polish argument that it was applying positive discrimination.
It also rejected a provision that gave the justice minister the power to decide whether particular judges could continue to practise once they had reached the new retirement age, because the reasons would have been "vague and unverifiable".
Why this is not the end of the story
By Adam Easton, BBC Warsaw correspondent
The Court's ruling is another blow for the PiS in its long-running dispute with the European Commission over judicial reform.
In June, the Court of Justice ruled that Poland broke EU law by lowering the retirement age for Supreme Court judges too, a change that forced about one third of Supreme Court justices into early retirement. In both cases, Law and Justice reversed the changes before the Luxembourg court announced its ruling, so in practice today's ruling changes little.
The truly landmark ruling is due to be announced later this month, in a case that will go straight to the heart of PiS' judicial reforms.
Polish judges are nominated by the National Judicial Council (NCJ), a body that is supposed to safeguard the independence of the judiciary, and which until recently consisted of a majority of judges selected by their peers.
In 2018, the ruling party changed the law so that the majority of judges sitting on the NCJ were appointed by the lower house of parliament, which Law and Justice controls. This has led to Poland's NCJ having its membership of the European Network of Councils for the Judiciary suspended on the grounds it is no longer politically independent.
The case also affects Poland's Supreme Court because another government reform created two new chambers for the court that have been filled by judges nominated by the new, politically appointed NCJ.
If the Court rules that those changes broke EU law, as a legal adviser to the court has already said, then the government could be forced to reverse some key elements of its judicial reform.
Why Poland is remaining defiant
Poland's government, re-elected only last month, is still trying to change the make-up of the judiciary.
On Monday the government nominated three new judges, including two former hardline Law and Justice MPs, to Poland's Constitutional Court.
One of the nominees is former communist-era prosecutor, Stanislaw Piotrowicz, who prosecuted an opposition activist during the 1980s. Critics have pointed out that a key justification for the ruling party's judicial reforms was the need to weed out communist-era judges, Adam Easton reports.
Another nominee, Krystyna Pawlowicz, has targeted Poland's opposition, using vocabulary such as "homos" and "eco-terrorists".
Poland's confrontation with the EU's executive body is also set to continue.
In April, the European Commission referred Poland to the Court of Justice again, accusing the government of undermining the independence of Polish judges.
The Commission said Polish judges were being subjected to disciplinary investigations on the basis of their judgements and it argued that the disciplinary process was overseen by judges selected by a panel appointed by MPs.