Three of the five judges presiding at the Swiss Supreme Court on Friday voted to overthrow a lower court's ruling last year, giving the green light for Swiss tax authorities to provide the data to their French counterparts, while blocking use of the data as evidence against the bank itself.
The Supreme Court's ruling is being closely watched for the impact it might have on the Swiss bank's 4.5 billion euro (£4.03 billion) legal battle with France in a criminal case over alleged tax avoidance by UBS clients.
Revenue-hungry governments, for years thwarted by Switzerland's strict secrecy rules, are also likely to be monitoring developments to see if they can use historical evidence of their citizens trying to hide money from tax authorities.
The Swiss Bankers Association said the decision could increase the risk of governments sending out requests simply fishing for information, adding that there could also be a danger of data being used for other purposes.
Although Switzerland exchanges bank account data on existing clients with dozens of countries to crack down on cross-border tax cheats, court cases such as the UBS dispute with France are highlighting potential legacy issues in Europe.
Italian authorities this year asked Swiss banks to provide information about their Italian business and in 2017 asked their Swiss counterparts for information regarding thousands of Italian citizens with accounts held in Switzerland.
The judges involved in Friday's oral deliberation said the written ruling must state that transferred data cannot be used in the ongoing criminal case against UBS in France, upholding a stipulation that information obtained via legal assistance may only be used for the purpose stated in the original request.
Switzerland's finance department said it would carefully review the verdict.
"Also, in the future, every request will be reviewed carefully to determine whether conditions for transmitting data are fully met," Swiss President Ueli Maurer said in a statement.
UBS said it would also undertake a careful review of the written verdict that will follow the oral decision, adding that Swiss authorities must ensure data is used only for the intended purposes - in this case, checking whether clients had paid their taxes.
"Regardless of the decision, it is important to note that the Swiss Federal Tax Authority will have to ensure that any data cannot be used against UBS in its pending criminal proceeding in France," the bank said in a statement.
"This was also the clear expectation of the court today."
UBS is appealing against the 5.5 billion euro penalty imposed by a French court that found the bank guilty of soliciting clients illegally and laundering the proceeds of tax evasion. The bank has denied any wrongdoing.
Friday's ruling was welcomed by one attorney from France's National Financial Prosecutor's Office, which is prosecuting the criminal case against UBS.
"The ruling is a positive signal for international cooperation," the official said.
The French tax authority also welcomed the decision and told Reuters it would use the information as foreseen by a Franco-Swiss tax treaty. It declined to comment on whether it had made similar information requests relating to other Swiss banks.
(Reporting by Angelika Gruber and Silke Koltrowitz in Lausanne, Oliver Hirt and Brenna Hughes Neghaiwi in Zurich and Inti Landauro in Paris; Editing by Susan Fenton and David Goodman)
By Silke Koltrowitz, Angelika Gruber and Brenna Hughes Neghaiwi