"This comes as a surprise as the market expected a further multibillion loss in the region between 2 billion to 7 billion Swiss francs," said Landsbanki Kepler analyst Dirk Becker.
But its investment bank continued to lose money, and further market deterioration led to writedowns and losses on previously disclosed risk positions, in particular in its monoline insurance exposures, UBS said in a statement.
UBS shares, which this week hit 10-year lows, soared on the earnings update but a downgrade by rating agency Moody's wiped out those gains, dragging the shares down 2.6 percent to 20.48 francs at the close.
The downgrades on UBS's financial strength, senior debt and deposit ratings reflected the challenges management face to return the bank to a position of stability following the losses in its investment banking, Moody's said.
"The bank has initiated many changes to senior management, risk management, and ... corporate governance, but it is not yet clear whether these changes will be effective considering the complexity of the task," said Moody's Senior Credit Officer Elisabeth Rudman.
The expected second-quarter result compares with a loss of 11.5 billion francs in the first quarter, when UBS also announced fresh writedowns, dumped its chairman and sought more emergency capital.
"The best news from these results is that the outflow of money from Wealth Management diminished during the quarter, indicating that its core franchise has remained resilient in the crisis," said Helvea analyst Peter Thorne.
UBS now expects its Tier 1 capital ratio to be about 11.5 percent at the end of the quarter and reiterated that it has no need to raise new equity.
"The results reflect positive contributions from global wealth management and business banking and from global asset management, offset by a loss in the investment bank," UBS said.
Earlier in the week, UBS said it was shaking up its board as it struggles to get back to its feet, but it is still not entirely over its problems.
The bank confirmed some of the market's fears, saying it had suffered a net outflow of money in the second quarter.
"This was most pronounced in April but improved in May and June, in particular for global wealth management and business banking," it said.
Some saw this as proof that the bank's problems in investment banking as well as its legal troubles with U.S. tax authorities are bleeding through to hurt its core business of managing money for the rich.
"The outflows are a result of the tax evasion scandal and a loss of client confidence," another Zurich-based trader said.
Earlier in the week news that UBS was mulling a sale of its U.S. broker Paine Webber had worried investors that more bad news could be on the way.
UBS will release its second-quarter results as planned on Aug. 12, the bank said.