By Francesco Guarascio and Michele Sinner

LUXEMBOURG (Reuters) - The European Union's top court ruled on Tuesday that junior creditors and investors need not necessarily suffer losses before a bank is rescued, a judgment that could affect Italy's plans to bail out its banks.

The ruling, in a case brought by investors whose savings were wiped out in Slovenia's 2013 rescue of local banks, is crucial to understanding how new EU "bail-in" rules are rolled out across the region.

Adopted after the 2007-8 financial crisis forced governments to stump up billions to rescue struggling lenders, the new rules require that private investors must take losses before banks can be rescued at taxpayers' expense.

The ruling knocked Italy's battered bank shares, traders told Reuters, leaving them down 1.8 percent at 1415 GMT [0#.FTIT8300]. Italian bank shares have lost about 50 percent of their value this year.

While the judges in Luxembourg made clear that imposing losses on investors was legally sound, they appeared not to require that this happen automatically.

In a statement, the court said a member state "is not compelled to impose on banks in distress, prior to the grant of any State aid, an obligation to convert subordinated debt into equity or to effect a write-down of the principal of that debt".

But governments and rescued banks "take the risk that there will be a decision by the Commission declaring that aid to be incompatible with the internal market", it warned.

The EU's executive Commission said the court decision would not affect talks with Rome over its plans to pump public funds into Italy's weakest lenders, including Monte dei Paschi di Siena <BMPS.MI>, which holds 47 billion euros of bad loans.

Rome wants to rescue its banks while protecting investors, big and small.

Competition commissioner Margrethe Vestager made clear that the final say would be with the Commission, while a spokeswoman said the court had "specifically confirmed that the Commission is justified in introducing burden-sharing principles as a key condition to approve the aid".

The Italian finance ministry and the Bank of Italy declined to comment on the ruling.

Italian banks have struggled for years, and with pressure on them increasing recently, Rome has hastened efforts to get European blessing for a state rescue.

The government fears that imposing losses on creditors -- chiefly holders of subordinated debt -- would undermine faith in its economic management and trigger protests ahead of a crucial autumn referendum on constitutional reform.

Rome did force creditors to take losses as part of the rescue of four small lenders in November, a move that was followed by mass protests and the suicide of one saver.

German Finance Minister Wolfgang Schaeuble has warned against a discussion about support for Italian banks before the European Central Bank publishes stress test results on July 29, although many investors want to see a solution before then.

The yield on Slovenia's 10-year benchmark bond fell to a 16-month low of 0.826 percent after the court ruling, on hopes that the state would not have to compensate bailed-in bondholders in state-owned banks.

(Reporting by Michele Sinner; additional reporting by Valentina Za and Giselda Vagnoni in Rome; Writing by Francesco Guarascio; Editing by Catherine Evans)