Thanks to lower legal costs, Bank of America's (BAC -0.13%) second-quarter earnings handily beat analyst expectations and drove the company's best quarterly performance since the onset of the financial crisis nearly seven years ago.

For the three months ended June 30, the nation's second-biggest bank by assets earned $5.3 billion, or $0.45 per share. That was more than double Bank of America's profits of $2.3 billion, or $0.19 per share, in the same period last year.

Analysts were expecting the bank to earn $0.36 per share.

"Solid core loan growth, higher mortgage originations and the lowest expenses since 2008 contributed to our strongest earnings in several years, as we continued to build broader and deeper relationships with our customers and clients," said CEO Brian Moynihan. "We also benefited from the improvement in the U.S. economy, where we are particularly well positioned."

Bank of America's break-out quarter was fueled first and foremost by higher revenue. The top line at the North Carolina-based bank increased by 1.7% to $22.1 billion compared to the year-ago period.

Higher income from lending operations provided the necessary boost. Breaking from its too-big-to-fail rivals Wells Fargo (WFC -0.56%) and JPMorgan Chase (JPM 0.49%), both of which reported lower lending margins yesterday, Bank of America generated proportionally more from its portfolio of interest-earning assets in the latest quarter than it did in the same period last year.

Its net interest margin -- income from interest-earning assets divided by the quantity of assets -- came in at 2.37% versus 2.22% last year. Bank of America said the increase stemmed from "positive market-related adjustments, primary from the company's debt securities portfolio, due to the impact of higher long-term interest rates."

The bank's fee-based income didn't fare as well. For the three-month period, Bank of America's noninterest income fell by $105 million, or 0.89%, on a year-over-year basis. Declining revenue in investment banking and trading, as well as changes in the value of available-for-sale securities, more than offset a near-doubling of Bank of America's mortgage banking income for the quarter.

But aside from the growth in lending margins, the biggest news this quarter concerned the bank's expenses. Bank of America has struggled to trim its bloated expense base for much of the past decade, but legal costs have stymied its efforts. This wasn't the case in the latest quarter, when legal costs fell by roughly 95% compared to the second quarter of 2014.

The net result is that Bank of America's efficiency ratio, which shows how much it costs a bank to generate each dollar of revenue, plummeted from 85% last year to only 62.5% this year. This puts the bank on the precipice of breaching the 60% threshold that separates the nation's most profitable lenders from their less profitable peers.

Higher revenue and lower expenses also pushed Bank of America to the edge of yet another important benchmark. On an annualized basis, its net income equated to 0.99% of its total assets, which is just shy of the 1% threshold that characterizes the healthiest banks. In the year-ago period, by contrast, its return on assets was only 0.42%.

When factoring in Bank of America's leverage, the company reported a 8.75% return on equity. This was dramatically better than it has been over the past few years, but still short of the 10% mark that generally dictates whether or not a bank's shares trade for a premium to book value.

In sum, Bank of America broke with precedent in the second quarter by finally giving shareholders a hint of its underlying earnings power. Shares of the bank were up more than 3% on the news Wednesday morning.