Bank of America Corp reported a third-quarter profit, boosted by accounting gains, but its main businesses struggled as income from lending and investment banking fell.

But the bank's shares rose as some analysts and investors were heartened by higher-than-expected profit and an increase in quarterly revenue. The stock, which has been volatile, has fallen more than 50 percent since mid-January.

Earnings were very good -- surprisingly good -- especially the revenue, surprisingly good in a very tough quarter, said Tim Ghriskey, chief investment officer at Solaris Asset Management in Bedford Hills, New York.

Asset sales contributed to Bank of America's ceding its ranking as the largest U.S. bank by assets to JPMorgan Chase & Co . BofA fell to No. 2.

Chief Executive Brian Moynihan is under pressure to prove he is turning around the Charlotte, North Carolina-based bank, which has been besieged by mortgage losses and lawsuits.

Moynihan has secured a $5 billion investment from Warren Buffett's Berkshire Hathaway Inc and plans to slash 30,000 jobs over the next few years.

But the bank has faced a backlash over its plan to charge customers $5 per month to use debit cards. Many shareholders also remain unconvinced about Moynihan's plans, especially if asset sales reduce potential sources of revenue.

The key then now is going to be, as revenues are going to be more subdued, is to get more cost out, Moynihan said on a conference call.

In late-morning trading, Bank of America shares were up 38 cents, or 6.3 percent, to $6.41. Their 52-week high is $15.31 last January 14, Reuters data show.

GAINS HELP, CORE RESULTS SUSPECT

Quarterly net income for shareholders was $5.89 billion, or 56 cents per share, compared with a loss of $7.65 billion, or 77 cents per share, a year earlier, when the bank took a $10.4 billion accounting charge. Revenue rose 6 percent to $28.7 billion.

Bank of America recorded $9.8 billion of pretax benefits from two accounting gains and from selling China Construction Bank Corp <601939.SS> shares. It also took a pretax loss of $2.2 billion for private equity and strategic investments.

Excluding one-time items, profit was 25 cents per share, according to Barclays Capital analyst Jason Goldberg. Analysts on average expected 19 cents per share, according to Thomson Reuters I/B/E/S.

Net interest income fell to $10.74 billion from $12.72 billion a year earlier, while net interest margin, or what the bank makes in loan interest versus what it pays for deposits, shrank to 2.32 percent from 2.72 percent.

I'm not very pleased with the results, said Bill Hassiepen, senior analyst at credit rating agency Egan-Jones Ratings Co. Core earnings appear very suspect.

Other major banks such as JPMorgan and Wells Fargo & Co also posted shrinking margins. Quarterly profit rose at Wells Fargo and at Citigroup Inc but fell at JPMorgan.

Bank of America's noninterest expense, excluding a goodwill writedown a year earlier, rose 4.7 percent to $17.6 billion.

Total employment edged up to 288,739 on September 30 from 288,084 three months earlier, but about 2,000 employees have been told they will be let go.

MORTGAGES, INVESTMENT BANKING WEIGH

The overhang from Bank of America's mortgage exposure persisted: the mortgage unit lost $1.1 billion in the third quarter, nearly triple the $392 million loss a year ago.

Analysts believe the bank's $2.5 billion purchase in 2008 of Countrywide Financial Corp, once the largest U.S. mortgage lender, has cost more than $30 billion because of writedowns and lawsuits, and that the figure could rise further.

The unit recorded $500 million of pretax litigation expenses. And despite a boom in home refinancings, the bank originated just $33 billion of home loans, down from $40.4 billion in the prior quarter and $71.9 billion a year earlier.

We are working very hard to continue to work through the delinquent portfolio, Moynihan said. There do continue to be some open items on mortgage. But we feel like we have done everything we can at this point.

Thompson said the bank expected to continue selling pieces of its mortgage servicing rights, and should finish shedding its correspondent mortgage business by year-end.

As global dealmaking dried up, the bank's global banking and markets unit lost $302 million, compared with profit of $1.56 billion in the prior quarter and $1.47 billion a year earlier. Revenue from investment banking and trading fell 36 percent and 22 percent, respectively, from the second quarter.

That unit comprises much of Merrill Lynch & Co's former operations that Bank of America bought at the height of the 2008 global financial crisis. It had been a key source of profit as other businesses hemorrhaged money.

Results from credit cards also weakened, as profit fell 35 percent from the second quarter to $1.26 billion.

(Reporting by Rick Rothacker and Joe Rauch in Charlotte, North Carolina; Additional reporting by Edward Krudy and Jonathan Stempel in New York; Editing by Ted Kerr and John Wallace)