Judges at the Luxembourg court were responding to a challenge to the bloc's so-called "conditionality mechanism" by Hungary and Poland.
What did the court say?
In a statement reflecting the decision, the court said that while the Commission must comply with strict procedural requirements, it had the right to withhold funds to sanction member states.
"The court dismisses the actions brought by Hungary and Poland in their entirety," the ECJ said.
The judges said that "compliance by the member states with the common values on which the European Union is founded... such as the rule of law and solidarity, justifies the mutual trust between those states."
"The [European] Union budget is one of the principal instruments for giving practical effect, in the European Union's policies and activities, to the fundamental principle of solidarity between member states."
Brussels claims vindication
The European Commission chief Ursula von der Leyen welcomed the decision saying that it vindicated actions taken so far by Brussels.
"Today's judgments confirm that we are on the right track," von der Leyen said in a statement.
"The Commission will now analyze carefully the reasoning of the judgments and their possible impact on the further steps."
German Foreign Minister Annalena Baerbock said that, as the foundation stone of the EU, rule-of-law needed protection.
"Violations not only cost our credibility, but our cohesion," said Baerbock. "Today's ECJ judgment confirms another important tool for the EU to protect and strengthen our community of values."
Budapest and Warsaw slam ruling
Polish Deputy Justice Minister Sebastian Kaleta tweeted that there was a need for "unity against the attack on our sovereignty."
"Poland must defend its democracy against blackmail aimed at taking away our right to self-determination."
Hungarian Justice Minister Judit Varga dismissed the ruling as a "political judgment" and proof that the EU was abusing its power.
"The ruling is another application of pressure against our country because we passed our child protection law during the summer," Varga wrote in reference to a controversial law that forbids the depiction of homosexuality or gender change to minors in media content.
Why was the case brought?
The two countries had launched an appeal against the sanctions mechanism, which aims to punish rule-of-law violations in member states by withholding funding earmarked for those countries.
Both countries are major recipients of EU funds and feared that the European Commission would use the sanctions against them.
Brussels introduced the measure after accusations that Budapest and Warsaw have undermined democratic standards, such as judicial independence.
Although the mechanism has been in place since the start of 2021, the Commission said it would wait for Wednesday's ruling before activating the procedure.
The delay had been agreed with Hungary and Poland in 2020 as a concession at the time for urgent agreement on important EU budget decisions.
What have Hungary and Poland done?
The European Commission sent formal letters to Warsaw and Budapest in November, outlining what it considers to be democratic shortfalls.
In the case of Poland, Brussels criticizes judicial reforms that it claims undermine the independence of judges and a refusal by Warsaw to accept the primacy of EU law over Polish law.
When it comes to Hungary, the Commission cites concerns over the issuing of public contracts, conflicts of interest and corrupt spending of EU funds.
For months, the European Parliament — which approves the EU's multi-year budgets — has urged the Commission to cut the funds immediately.
It says the countries have long passed the threshold at which the mechanism should be launched. The legislature has even launched its own legal proceedings against the Commission, accusing it of inaction.
However, the EU executive — wary that it might fall foul of legal challenges — has preferred to gradually build a case it hopes will be unassailable.
The Commission would need the votes of most member states to approve the mechanism's use under qualified majority voting.
rc/fb (AFP, dpa)