The European Union’s highest court has ruled that Poland broke the law when it sought to lower the retirement age for judges, in a further defeat for the country’s nationalist government.

The European court of justice (ECJ) found that a 2017 policy to lower the retirement age for ordinary judges in Poland was unlawful because it gave too much power to the executive, and ruled that a decision to compel female judges to retire five years earlier than men broke EU equality law.

The law was changed after the outcry, but Polish authorities never reinstated the judges that lost out as a result of the original decision.

The judgment is likely to be privately welcomed by some EU member states, such as France and Germany, who have watched in alarm as Poland’s government has sought to increase control over the courts.

Since taking office in 2015 the nationalist Law and Justice party has been on a collision course with the EU over the rule of law. The government has assumed direct oversight of state prosecutors and the judicial body that appoints, promotes and disciplines judges.

The latest ruling is the second landmark judgment against Poland’s judicial policy in recent months. In June the ECJ found that a 2018 law to force the retirement of 40% of supreme court judges was in breach of EU law.

Tuesday’s judgment addressed the 2017 law that lowered the retirement age for ordinary judges and public prosecutors to 65 for men and 60 for women, down from 67 for both sexes.

The court also objected to a provision in the 2017 law that empowered Poland’s justice minister to allow some judges to work beyond the statutory retirement age. It said the minister would be able to make decisions on “vague and unverifiable” criteria and would help to create “reasonable doubts” that the new system “might have been intended to enable the minister to remove … certain groups of judges while retaining others in post”.

Poland’s government said the court should have withdrawn the complaint, after it changed the law in 2018. It said the judgment “concerns a historical condition which does not reflect the current provisions”, a reference to the 2018 amendment that equalised the retirement age for male and female judges.

The European commission, which launched the legal action against Poland, welcomed the ruling, saying: “This is an important ruling in support of the independence of the judiciary in Poland and beyond, as well as to prevent discrimination on the basis of gender.”

The commission called on the Polish government to provide redress to those judges and prosecutors who lost their jobs. The commission’s chief spokeswoman, Mina Andreeva, said the lack of “redress mechanism provided despite the change of law” was the remaining issue. She added: “We will monitor what the Polish government does in response. The judgment is very clear and we expect the Polish government to comply with this judgment.”