The US and Switzerland have signed an agreement designed to end a tax evasion dispute surrounding UBS's US customers.
The Swiss banking giant will now give the US tax authorities the details of 4,450 accounts, US officials said.
Internal Revenue Service Commissioner Doug Shulman said the accounts held $18bn in assets at one time, and many have since been closed.
Hours after the deal was agreed the Swiss government said it was putting its 9% stake in UBS up for sale.
The stake is currently valued at about 5.56bn francs ($5.22bn; £3.16bn).
The government says the sale will recoup a 6bn franc investment it made in the bank last October.
The US Justice Department had been originally seeking the names of 52,000 US customers with Swiss accounts.
The IRS said that the names being handed over were the ones most suspected of hiding undeclared assets in Switzerland.
"I believe this agreement gives us what we wanted - access to information about those UBS accountholders most likely to have been involved in offshore tax evasion," Mr Shulman said.
Washington said last week it would end its legal action in the US against UBS once the final deal was signed.
"The out-of-court agreement avoids a prolonged legal battle that would have had an uncertain outcome, and UBS can now continue with its consolidation process in an atmosphere free of this legal uncertainty," the Swiss Bankers Association said.
The deal looks set to end a stand-off that has lasted months.
In February, UBS admitted to tax fraud in the US and agreed to pay $780m (£467m) as part of a provisional deal to settle charges that it helped thousands of US clients use Swiss bank accounts to evade taxes.
UBS also handed over a limited number of account details, but US officials argued this was not enough and launched a fresh legal challenge to obtain the identities of all the bank's US account holders.
The US accused UBS of hiding nearly $15bn in assets of US customers.
Two legal regimes
UBS had been caught between two legal regimes, essentially violating US tax laws if it had not disclosed the names and violating Swiss secrecy laws if it did.
But US Justice Department attorney Stuart Gibson told a US court last week the two sides had now reached an out-of-court settlement.
Switzerland has long been famous for its status as a tax haven.
Swiss Justice Minister Eveline Widmer-Schlumpf told reporters in Bern that the deal ends the threat of criminal prosecution against UBS and "there was no alternative to this solution".
The UBS customers whose names are to be given to the US tax authorities will be able to challenge the hand-over of their identities before Switzerland's Federal Administrative Court, Mrs Widmer-Schlumpf said.
She said the agreement means that Swiss law "remains untouched".