By Ben Eisen

Bank of America Corp.'s profit tumbled 52% in the second quarter after the bank set aside billions of dollars to prepare for soured loans.

The Charlotte, N.C.-based bank said Thursday that it earned $3.53 billion, versus the $7.35 billion it made a year earlier. Per share, earnings of 37 cents were above the 28 cents that analysts polled by FactSet had forecast.

Profit was hit by an increase in the bank's provision for loan losses, reflecting concern across the banking industry that the recession resulting from the coronavirus pandemic will result in a wave of defaults.

The bank set aside $5.12 billion on top of the $4.76 billion it put away last quarter. The provision included an additional $3.97 billion that the bank set aside for future losses, as well as $1.15 billion for net charge-offs.

This recession has been unusual in that the federal government has provided unprecedented stimulus to help companies and consumers, and lenders have let customers temporarily skip debt payments. But bank executives are expecting defaults ahead as those programs wear off and the economy remains partially shut.

JPMorgan Chase & Co., Citigroup Inc. and Wells Fargo & Co., the other biggest U.S. banks, collectively socked away $28 billion in the second quarter for loan losses. Bank of America, the second-largest U.S. bank by assets, has a giant U.S. customer base that makes it especially sensitive to the state of the economy.

While the bank expects a deep recession, Chief Executive Brian Moynihan sounded a more optimistic note than other bank executives about the economy. He said that while consumer spending was well below 2019 levels in April and May, it was about flat in June and higher in early July.

"As states began to reopen in the past couple months we saw an improvement in spending levels as customers became more active buying fuel and spending on home projects and eating out," he said on a call with analysts.

Bank of America said it processed some 1.8 million payment deferrals on consumer debt so far this year, mostly for credit-card customers earlier in the spring. Mr. Moynihan said he expects deferrals will decline unless the economy worsens significantly.

The bank posted revenue of $22.33 billion, down about 3% from a year earlier.

A bright spot was the bank's capital markets businesses. Extreme market turbulence in March was followed by buoyant stock and bond markets in the second quarter.

Adjusted trading revenue of $4.41 billion was up 35% from $3.27 billion a year ago. Wild markets also powered trading at rivals including JPMorgan and Goldman Sachs Group Inc.

Bank of America posted a 50% jump in fixed-income trading revenue, as well as a roughly 7% rise equities.

Total investment banking fees jumped 57% to a record $2.16 billion, led by an 87% rise in equity issuance. The bank's businesses that help companies issue debt and advise on mergers also had strong growth.

Companies in the second quarter rushed to sell stock and debt to shore up their finances as markets got back to normal and to take advantage of low interest rates.

Falling interest rates in recent months have made it more difficult for banks to profit by borrowing money at low rates and lending it out at a higher rate. Bank of America's net interest margin fell to 1.87% from 2.33% in the first quarter. The bank's net interest income declined 11% to $10.85 billion.

Its noninterest income, which includes fees and is less dependent on the level of rates, rose 5% to $11.48 billion.

Expenses in the second quarter increased slightly versus last year to $13.41 billion, as banks spent money setting up employees to work from home and safeguarding their branches.

Bank of America shares fell 3.9% in morning trading Thursday. The lender's stock has fallen more than 30% so far this year, slightly outperforming the 34% drop in the KBW Nasdaq Bank Index of large financial institutions.

Write to Ben Eisen at ben.eisen@wsj.com