Bank of America reported Wednesday a quarterly loss of $276 million due to $6 billion in legal expenses that included a huge settlement with the US on mortgage-backed securities.

The bank had revenues of $22.8 billion, compared with earnings of $1.5 billion on revenues of $23.4 billion in the period a year ago. Operating results were mixed and included weaker mortgage banking profits but higher investment and brokerage income.

"The cost of resolving more of our mortgage issues hurt our earnings this quarter," said chief executive Brian Moynihan.

"But the earnings power of our business and customer strategy generated solid results and we continued to return excess capital to our shareholders."

The US banking giant said $3.6 billion of the legal costs were associated with a $9.5 billion settlement with the Federal Housing Finance Agency to resolve charges that it sold bad mortgage-backed securities to mortgage giants Freddie Mac and Fannie Mae ahead of the housing bust.

The additional legal costs also went mostly to address other mortgage-related problems, the bank said.

Results in BofA's consumer real estate services division were hit by declines in mortgage refinancings, mirroring an industry-wide trend.

But on the positive side, BofA benefited from improving credit quality. It set aside $1 billion in provisions for credit losses, down from $1.7 billion a year ago.

The bank also reported higher profits for its global markets segment.

Bank of America shares were off 0.7 percent in pre-market trade to $16.27.