MADRID — Europe’s highest court ruled on Wednesday that customers of banks in Spain can reclaim billions of euros because lenders did not pass on savings from interest rate cuts on variable-rate mortgages, sending shares in several of the country’s top lenders crashing.

The ruling centered on the use of a “floor clause” in Spanish mortgage contracts during the aftermath of the global financial crisis. Such agreements meant that the interest rate on an adjustable-rate mortgage was always held above a predetermined level, regardless of how low central bank rates fell.

Spain’s lenders began to use the clauses in 2009, after the global financial crisis pushed central banks around the world to slash interest rates. That helped preserve bank profit margins but failed to pass rate cuts on to customers beyond a certain level.

In 2013, Spain’s supreme court ruled that such deals were illegal, in part because the country’s banks did not adequately explain them to customers. The court did not, however, penalize lenders retroactively.