Hungary and Poland have lost their court challenge in the European Court of Justice (CJEU) to an EU rule that makes funding conditional on democratic standards.
The CJEU has ruled that complying with the rule of law is a condition of enjoying membership of the EU.
The CJEU ruled that "sound financial management of the EU's budget" could be seriously compromised by breaches of the rule of law.
Hungary's governing party Fidesz said that the ruling was a political decision.
EU member states signed up to common values, such as the rule of law and solidarity, and the EU "must be able to defend those values", the ruling added.
Both countries have been investigated for undermining legal independence, media and non-governmental organisations.
Poland was ordered last year to shut down a disciplinary chamber for judges because it was not independent.