* Government wanted legal green light for borrower relief
* But court rules forex loans do not breach law
* Banks shares surge on court judgment
* Lenders now await next steps from government (Adds comment from ruling party, analyst)
By Krisztina Than and Gergely Szakacs
BUDAPEST, Dec 16 Hungary's supreme court ruled on Monday that banks are not to blame for borrowers losing out on foreign currency loans, reducing the risk that the government will make lenders foot the bill for a massive relief scheme.
But the government of Prime Minister Viktor Orban, facing an election early next year, has said it is determined to provide help to struggling holders of the foreign currency loans, and could still impose a new relief scheme on banks.
Hundreds of thousands of Hungarians took out mortgages denominated in euros or Swiss francs because they were the cheapest option available at the time, and then saw their debt balloon when the Hungarian forint fell in value.
A relief scheme is a potential vote-winner for Orban, but a menace for foreign banks, including Raiffeisen, Erste Bank and Unicredit. They are already reeling from a previous, government-imposed relief scheme.
Markets interpreted the ruling from the court, known in Hungary as the Kuria, as a reprieve for the banks.
Shares in Hungary's biggest bank, OTP surged 5 percent after the ruling, before falling back to around 2.8 percent.
"The 'worst case' scenario can be likely ruled out," said Eszter Gargyan, an analyst at Citigroup. She said the ruling made it unlikely that banks would have to swallow the full loss on forex loan contracts due to the exchange rate shift.
In September, foreign currency mortgages in Hungary, both property loans and equity loans, totaled some 3.5 trillion forints ($15.8 billion) in value - or about 10 percent of the country's gross domestic product.
The ruling Fidesz party's parliamentary group leader Antal Rogan said the court ruling was a disappointment. "With this decision the highest judicial panel has ... sided with the banks," Rogan told a news conference.
He said the court's ruling still left some questions unanswered about the legal status of the forex loans, and that the government would wait until this was cleared up before deciding what action to take.
Far-right opposition party Jobbik stepped up pressure on the government, saying it would organise nationwide rallies in support of foreign currency borrowers if the government did not take measures to help them.
In its judgment, the court said that borrowers who took out the loans must bear the impact themselves of exchange rate fluctuations.
"Just on the basis of the exchange rate risk for the borrower, this type of contract is not against the law or good morals and is not usury," Judge Gyorgy Wellmann told reporters after a sitting of the court.
The judge said, in guidance to lower courts, that if legal problems were found with a forex loan, that did not automatically render the contract void.
One aspect of the court's deliberations on the loans is still pending. That is on the question of whether the banks were sufficiently transparent about unilateral changes to the loans, for example, hiking interest rates.
The court said it would address that issue after the European Court of Justice had made its decision in a related case.
With a two-thirds majority in parliament, Orban is Hungary's most powerful leader since the fall of Communism.
He frequently sweeps opposition aside to push through his agenda, and has clashed often with the judiciary, which critics say is one of the few remaining checks on his power.
Zoltan Bodnar, an associate professor of financial law at Budapest's ELTE University, said the court had shown it was still independent.
"Despite strong political pressure, it has made a decision (today) purely on a professional basis," Bodnar said.
Earlier, Orban had urged the court to rule whether banks or borrowers should bear exchange rate losses on the loans. He has accused banks of duping clients and making vast profits at the expense of ordinary Hungarians.
For the banks, the reprieve provided by Monday's court ruling could be only temporary.
"The court has declared that the contracts are valid, but this in itself does not remove the risk of government measures that could bring significant additional costs for the banks," said Zsolt Kondrat at MKB Bank. ($1 = 219.9119 Hungarian forints) (Additional reporting by Sandor; Peto; Editing by Christian Lowe)