Citigroup Inc , one of the big U.S. banks hit hardest by the financial crisis, posted a quarterly profit on Friday as gains from the sale of its Smith Barney brokerage into a joint venture more than offset losses from its primary banking businesses.

Excluding the gains, the bank reported a second-quarter loss that was narrower than expected.

It's a mixed quarter. You weren't looking for a Goldman Sachs or JPMorgan-type of quarter, but we expected Citi to be a lot better than it was in recent periods, said Michael Mullaney, who helps manage $9 billion for Fiduciary Trust Co in Boston.

Like Goldman and JPMorgan, which delivered surprisingly strong earnings earlier this week, Citigroup reported some robust trading and investment banking results. Yet credit losses continue to be a drag.

They seem to be suffering more than other (banks) as far as losses go from credit cards, mortgages and consumer loans in general, Mullaney said.

Citigroup, propped up with a $45 billion government bailout, recorded a gain of $6.7 billion from merging Smith Barney into a joint venture with Morgan Stanley .

The gain boosted net income to $4.28 billion, or 49 cents a share, compared with a year-earlier loss of $2.50 billion, or 55 cents.

Excluding the gain, Citigroup lost $2.34 billion, or 26 cents a share. Analysts' average forecast was a loss of 31 cents a share, according to Reuters Estimates.

Revenue jumped 71 percent to $30.0 billion thanks to the $11.1 billion pretax Smith Barney gain as well as net write-ups on mortgages and other assets.

It is hard to say whether they've completely turned the corner, but they are heading in that direction, said Walter Todd, portfolio manager at Greenwood Capital Associates. Part of that is the economy bottoming out, and part of that is actions they have taken internally. I think they are more dependent on the macro situation continuing to improve.

Credit costs increased to $12.4 billion, including $8.4 billion of net losses and the addition of $3.9 billion to loan loss reserves. That brings the total allowance for loan losses to 5.6 percent of total loans.

POSITIVE SIGNS?

Even so, Citi officials said there are some signs that conditions have stopped their precipitous decline.

Chief Financial Officer John Gerspach told Reuters in an interview that there are signs of improvement in Citigroup's consumer loan portfolio. He also said he expects the bank to fare better than rivals as the credit cycle begins to hit commercial real estate, an area where Citigroup says it is less vulnerable than some competitors.

You can think of the credit cycle in three pieces: the wholesale securities piece, the consumer piece and the commercial real estate piece. As a relative matter, we have less exposure in the third area, Gerspach said.

Citigroup shares are down 94 percent since peaking in May 2007 and have fallen by half this year, but they have tripled since financial services stocks began rallying in March.

The shares were up 3 cents to $3.06 in late-morning trade on the New York Stock Exchange.

The iconic New York bank has been among the biggest losers in the nearly three-year financial crisis, prompting the U.S. government to step in with multiple bailout plans.

Chief Executive Vikram Pandit in January decided to split the company in two: Citicorp includes the global commercial bank and other businesses it wants to keep, while Citi Holdings is a collection of units and bad assets it will sell.

In the second quarter, Citicorp income from continuing operations fell 11 percent to $3.06 billion, driven mostly by plunging profit in regional consumer banking businesses.

The institutional client group, the company's investment banking and trading division, boosted operating income by 16 percent to $2.84 billion.

Citi Holdings posted operating income of $1.36 billion, compared with a loss of $5.23 billion a year earlier, as brokerage and asset management gains more than offset losses from consumer finance businesses and losses from winding down a portfolio of toxic debt.

Earnings attributable to common shareholders were reduced by $1.28 billion of preferred stock dividends to the U.S. government and other investors, compared with $361 million in the year-ago period.

The bank next week is expected to swap the U.S. government's preferred stock investment into a 34 percent equity stake in Citigroup. (Reporting by Joseph Giannone; Additional reporting by Steve Eder; editing by John Wallace)