The two countries had threatened to veto the bloc's €1.8 trillion budget and coronavirus recovery package after other member states insisted on controls to make sure payments could be stopped if countries breached rule of law.
Polish prime minister Mateusz Morawiecki and his Hungarian counterpart Viktor Orbán have been repeatedly criticised by the European Commission and leaders like Emmanuel Macron, who last week suggested Hungary was becoming an authoritarian state along the lines of Turkey.
But in a classic EU compromise brokered by officials on the eve of Thursday summit, the central European countries backed down from their veto threat in exchange for a delay in any sanctions and a process that could complicate any action against them.
Under the deal spelled out in a draft circulating in Brussels ahead of the meeting, the European Court of Justice would have to rule on the legality of the new approach, which could take more than a year, according to officials with knowledge of the situation. Leaders are expected to approve the deal at their meeting in the Belgian capital on Thursday, though civil society organisations in the two countries have said the settlement does not go far enough.
The saga has seen diplomats from countries worried about the authoritarian drift in the two states variously accuse their right-wing populist governments of treating the EU like a "cash machine", while pursuing policies and home that threaten liberal and democratic values.
Hungary's Mr Orban has openly spoken of his intention to break with "liberal democracy", passed laws to crack down on civil society organisations, and extended its control over the judiciary, while trafficking heavily in anti-immigrant rhetoric and policies.
Poland's government has been accused of undermining the independence of the country's judiciary, with the European Commission launching an infringement procedure against the country in April to safeguard the rule of law.
Mr Morawiecki warned last month that tying cash to democratic standards would be "extremely dangerous for European unity", arguing that it "creates the danger of the breakup of the union".
The watering-down of the rule of law mechanism is a win for Hungary and Poland, who are unlikely to be penalised under it under the coronavirus recovery is well underway. The compromise also states that the mechanism only applies to the 2021-2027 EU budget and recovery fund, meaning the issue will almost certainly be reopened down the line.
Hungarian Justice minister Judit Varga on Wednesday night described the deal as a "victory", adding: "We succeeded in separating ideological expectations from financial aid during a pandemic and prevented political blackmail.
"The deal respects the EU treaties and our national identity. Yet another triumph for the Hungary-Poland friendship! We will never give up and will always fight for Hungary!"
But despite the built-in delay, the rule of law mechanism is essentially unchanged, and for the first time explicitly links the disbursement of EU cash to democratic values. Once in force, it could be costly for both countries, especially in the later part of the EU's rolling seven-year budget.
Recognising this, Polish Justice minister Zbigniew Ziobro struck a different tonę to his Hungarian counterpart, stating that "if the regulation combining the budget with ideology enters into force, it will be a significant limitation of Poland's sovereignty and a breach of European treaties".
The compromise was brokered with the help of political pressure from Angela Merkel, who has previously warned Hungary's Mr Orban over his attitude to "the opposition, civil society and the media". Germany holds the rotating presidency of the EU's council, the bloc's forum for member state diplomacy. Diplomats say that the prospect of the EU having to pass an emergency budget if a veto was used has helped concentrate minds on both sides.
The financial package includes a €750 billion recovery fund aimed at helping the EU's economy recover from coronavirus, on top of its usual seven-year budget, or "multi annual financial framework" – together totally €1.8 trillion.
But the approach has left some civil society groups in both countries disappointed. Oktawiusz Chrzanowski, campaign director at the Polish campaign organisation Akcja Demokracja, said the deal meant "that Poles who have been fighting so hard for European values such as respecting the rule of law, independence of judiciary and human rights including women rights and LGBT+ rights are being left alone by European Union".
"We cannot agree to that. The mechanism as legally proposed and agreed to by the European Parliament cannot be overwritten by the European Council so that in Poland Morawiecki, Kaczyński and Ziobro can escape responsibility and continue to take full advantage of the perks of being part of the EU.
"They are already putting in place another wave of so called reforms to further damage Polish democracy, make all Polish judges dependent on the will of party leaders, weaken civil society and ensure their own inviolability. This can not happen and Europe mustn't give in: it is their obligation to not let autocrats divide, weaken and finally dismantle Poland and European project.”
Gergő Hajdú, campaign director at Hungary’s largest progressive campaign organisation aHang, said: “Mr Orbán keeps saying that he represents the interest of the Hungarian people. As a matter of fact, it's not true. He's representing himself and his own small circle of oligarchs and family who are the main beneficiaries of EU funds.
"There is no healthy competition, no innovation, no 21st century education, it's only the prime minister's small circle that he dominates that keeps him in power. Hungary is far, far away from the optimal utilization of EU funds because of him. Mr. Orbán rules with a two third majority with less than 50% of the votes. He is now trying to get away with a completely unacceptable compromise with Germany to secure his re-election in 2022. It’s not about Hungarian sovereignty, it’s not about a fight for ideological freedom, it is only about money to finance elections.
"If the compromise is accepted, the EU will experience how Mr Orbán or anyone else can take the European community hostage in the future. Again and again and again.”
The budget saga is the latest spat over how to enforce rule of law at EU level, amid concerns that some member states are jettisoning democratic norms. Critics like Emmanuel Macron say current protections are too unwieldily and need to be reformed, but the approach has been fiercely resisted by the countries doing the breaching, who also have as say in writing the rules.
Join our commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies