Hundreds of thousands of Poles took out mortgages in foreign currencies, mainly in Swiss francs, attracted by lower interest rates. They are now paying far bigger installments than expected after the Swiss franc soared against the zloty and following interest rate hikes in Switzerland.

The court ruling means that banks cannot charge for the cost of capital on foreign currency loans which were deemed invalid because they contained unfair terms, a verdict which had been expected by analysts.

"EU law does not preclude, in the event of the annulment of a mortgage loan agreement vitiated by unfair terms, the consumers from seeking compensation from the bank going beyond reimbursement of the monthly installments paid," the court said in a statement.

"By contrast, it precludes the bank from relying on similar claims against consumers."

While the cost to the Polish banking sector will be large, analysts have said it will be able to absorb the blow. The ruling was in line with an opinion from an adviser to the court which was issued in February.

"The threat to the ability to finance the economy is significant, but I would rule out the collapse of a bank or, even more so, the sector," said Tadeusz Bialek president of the Polish Bank Association, in a comment sent to Reuters before the verdict.

The court said in its statement that the argument about the stability of the financial markets is not relevant in the context of the interpretation of the directive, which is intended to protect consumers.

Polish financial regulator KNF said in a statement published after the verdict that the ruling was negative for the Polish banking sector and wider economy, but that the banking sector was safe.

"Banks have recently built an appropriate buffer increasing their resilience and ability to absorb the costs related to the unfavorable decision of the CJEU," it said.

"However, the erosion of banks' capital that will take place in connection with this decision will have a negative impact on banks' ability to continue to finance the housing needs of Polish households as well as the entire economy..."

Poland's WIG Banks index was down 2.4% at 0831 GMT.

($1 = 4.1129 zlotys)

(Reporting by Alan Charlish, Anna Wlodarczak-Semczuk, Pawel Florkiewicz, Karol Badohal; Editing by Frank Jack Daniel, William Maclean)

By Anna Wlodarczak-Semczuk