Switzerland's biggest bank, UBS, is to pay $780m (£547m) to the US authorities to avoid a criminal prosecution for helping thousands of wealthy Americans avoid tax by hiding their money in secret bank accounts.

In a settlement announced last night, UBS admitted breaking American law by participating in a scheme to defraud the US internal revenue service. The long-running case went to the heart of Switzerland's tradition of bank privacy. The US justice department had accused UBS of actively encouraging Americans to use its bank accounts to avoid paying tax.

In a highly unusual move, UBS has agreed to hand over the names and account details of certain American clients to the US government. It will pay $380m in disgorgement of profits and $400m to make up for unpaid tax.

UBS's chairman, Peter Kurer, said the bank "sincerely regrets" compliance failures identified in the case: "We accept full responsibility for these improper activities."

He said UBS was still committed to privacy: "Client confidentiality, to which UBS remains committed, was never designed to protect fraudulent acts."

Under US law, Americans are supposed to declare all foreign bank accounts containing more than $10,000. According to prosecutors, some 20,000 Americans had private accounts at UBS containing $20bn between 2002 and 2007. Some 17,000 of these accounts were concealed from the tax authorities.

UBS's reputation took a beating last year when a former private banking executive, Bradley Birkenfeld, pleaded guilty to helping a billionaire client evade tax. Birkenfeld made a series of lurid allegations about UBS's tactics.