Alan Diaz/Associated Press

Buoyed by one-time gains from accounting changes and the sale of assets, Bank of America reported a $6.23 billion profit for the third-quarter Tuesday, even as weakness on Wall Street hammered underlying results and the firm surrendered its position as the country’s largest bank by assets.

Still, it could have been worse, especially given the mortgage-related losses that have pounded Bank of America’s stock in recent months and caused investors to worry about its long-term strength. Bank of America shares rose nearly 6 percent in early trading.

The bank, based in Charlotte, N.C., reported net income of 56 cents a share, compared with a loss of $7.3 billion or 77 cents a share in the year-earlier period. Analysts had been expecting the bank to earn 28 cents a share in the third quarter. Revenue rose to $28.7 billion from $26.9 billion, although that too was pumped by one-time gains.

Without the special items, Bank of America would have earned about $2.7 billion, which includes $1.7 billion in reserve releases as credit losses eased.

Total assets stand at $2.22 trillion, compared with $2.29 trillion for JPMorgan Chase, which now holds the title of the largest American bank. JPMorgan is also the biggest bank by deposits, with $1.1 trillion compared with Bank of America’s $1.04 trillion deposit base.

Related Links The press release

Although Bank of America Merrill Lynch has been a crucial source of profit recently as other businesses like mortgages hemorrhaged money, the slow trading environment and financial uncertainty in Europe caused trading revenue to drop. The company’s global banking and markets revenue fell to $5.2 billion from $7 billion, and the unit reported a $302 million loss in the third quarter, a sharp contrast to the $1.46 billion gain a year ago.

For investors, the red ink flowing from Bank of America’s disastrous acquisition of Countrywide Financial in 2008 remains the biggest worry.

Both the federal government and private investors are seeking compensation for tens of billions of dollars in losses on securities backed by subprime mortgages, while also trying to force the bank to buy back soured home loans, arguing the mortgages were improperly originated and bundled into securities.

Provisions for so-called put-backs, in which investors try to force the bank to buy back soured mortgages by arguing they were improperly originated and bundled into securities, fell to $278 million. In the second quarter, these provisions totaled a whopping $14 billion, including an $8 deal billion with investors that include the Federal Reserve Bank of New York.

The chief executive of the bank, Brian T. Moynihan, said, “This quarter’s results reflect several actions we took that highlight our ongoing transformation toward becoming a leaner, more focused company.”

Mr. Moynihan is in the midst of a huge effort to sell noncore businesses and build up Bank of America’s underlying capital, and these efforts were reflected in a $3.6 billion gain from the sale of half its stake in the China Construction Bank, as well as the unloading of assets like the company’s Canadian credit card business and a stake in HCA, the hospital giant.

The bank put its exposure to Greece at $485 million, most of it in loans that don’t include the country’s government debt, and more than $10 billion total exposure to Italy and Spain.

The other major commercial banks that have reported earnings in recent days posted profits of around $4 billion each. Both Citigroup and JPMorgan Chase benefited from a $1.9 billion increase from the accounting change applied to the declining value of their company debt, posting profits of $3.8 billion and $4.3 billion, respectively. Wells Fargo had record earnings of $4.1 billion despite a 6 percent drop in revenue.