Poland's lower house of parliament has voted through controversial new reforms which will see all Supreme Court judges removed and replaced.
The Law and Justice Party say it will make the judicial system more effective and able to fight against corruption.
But critics say it is a threat to the rule of law, placing control of the judiciary in the hands of politicians.
Donald Tusk, European Council President and former Polish prime minister, said the changes are "backward".
'The day judicial independence died'
In a statement released after the vote, Mr Tusk said he had asked Poland's President Andrzej Duda for a meeting to discuss the changes, which he warned went against European values and risked marginalising the country.
The bill, which will now go to the upper house on Friday after being passed by 235 votes to 192, will see all Supreme Court judges forced into retirement.
The decision on whether or not they can have their jobs back will, on the face of it, be the president's, but in reality he will be acting on the advice of the justice minister.
The National Judiciary Council, which currently nominates both common and Supreme Court judges and consists of judges selected by professional legal bodies, will now be chosen by parliament - but its member judges will require at least three fifths of representatives to back them in order to be selected.
Last week, the ruling Law and Justice party pushed through parliament plans for MPs and the justice minister to have the power to appoint judges.
Then President Duda, a former member of the right-wing, populist ruling party, proposed a compromise to make it harder for a single ruling party to change the make-up of the 15-member National Council of the Judiciary.
Some critics were won over but others feared the compromise did not go far enough - especially as it is likely the ruling party may be able to get the support of smaller parties it often sees eye-to-eye with.
After Thursday's vote, Grzegorz Schetyna, leader of Poland's largest opposition party, Civic Platform, called it the day judicial independence died, while political analyst Stanislaw Mocek warned news agency AFP that subjecting "the judiciary to political power.... paves the way for a non-democratic system in Poland".
Thousands of people have also taken to the streets to protest the bill in recent weeks.
Analysis: A system in need of reform - but maybe not like this
Adam Easton, BBC News, Warsaw, Poland
Most Poles agree that the courts need reform, in fact an opinion poll in May found 63% said so. For many, Polish courts operate too slowly and sometimes deliver questionable verdicts. In its election manifesto Law and Justice promised to reform the courts. But is this the reform so many people want?
Not even rock star turned politician Pawel Kukiz, who leads the Kukiz '15 party and who said he could not vote against the bill, thinks so. "This is not reform, it's just changing the personnel," he said before the vote.
Certainly many Poles feel the reforms give Law and Justice the tools to destroy judicial independence and appoint judges sympathetic to the party. They are the ones taking to the streets every evening in cities across the country to join candle-lit protests and appeal to the president to veto the legislation. Unlike previous demonstrations they are less obviously party political and perhaps as a result, it seems more young people are turning up.
The European Commission has issued Poland's government with a stern warning, complaining that its plans "collectively would abolish any remaining judicial independence and put the judiciary under full political control of the government". Commission Vice President Frans Timmermans even threatened the "nuclear option" of withdrawing Poland's voting rights in EU meetings. That has never been used before.
After the vote, Mr Tusk released an impassioned statement, saying the recent moves "transport us - in the political sense - in time and in space: backwards and eastwards".
He argued a solution must be found "which is acceptable to the Polish public, to the parliamentary majority and to the opposition, to the President and to the European Union".
But Hungary's Foreign Minister Peter Szijjarto warned the commission should not "act like a political body", adding: "We stand by Poland, and we call on the European Commission not to overstep its authority."