"Spanish legislation infringes EU law to the extent that it precludes" a court from declaring the terms of a loan agreement to be unfair, thereby halting a mortgage foreclosure process, the ECJ said in a statement.
Additionally, if a court rules a loan agreement to be unfair after the eviction has taken place, the mortgage holder can only use that ruling to seek later financial compensation and "is unable to recover ownership of his property."
In Madrid, the government promised Thursday that "all the aspects that the court has declared to be contrary to European legislation will be corrected."
Thousands of people have fallen foul of the law and been evicted as Spain struggles in a deep recession which has pushed unemployment to record highs of 26 percent.
The banks, which offered cheap funding to home buyers and developers, have been desperate to get their loans back since a massive property bubble burst in 2008, sparking a wave of defaults.
In response to popular protests and reported suicides, Spain's government in November passed a two-year moratorium on evictions — but campaigners insist that it go further.
Protestors last month brought a motion to the Spanish parliament, backed by 1.4 million signatures, for an end to evictions and to allow insolvent homeowners to write off their debts by surrendering their home.
Under current Spanish law, a bank can pursue a mortgage holder to pay off the remaining balance of a loan if the value of the seized property is not sufficient.