JPMorgan Chase is battling a slew of lawsuits. And its sky-high legal costs led to a loss of $400 million during the third quarter, the first loss since Jamie Dimon took over as CEO in 2004.

The bank's legal tab for the third quarter was $7.2 billion after taxes. Dimon called the quarterly loss "painful" and warned that litigation costs could continue to be a drag on earnings for several quarters.

But Dimon also noted the bank "had strong underlying performance across the business." The legal expenses should not hurt the bank's ability to buy back stock or issue dividends, he said.

Excluding its legal tab, JPMorgan Chase reported a quarterly profit of $1.42 per share, easily beating Wall Street's forecasts.

Investors were relieved at first to have more clarity on the size of potential losses. The stock rose in early trading. But by late morning, shares of JPMorgan Chase (JPM) were down modestly.

Related: JPMorgan working to contain damage as massive settlement looms

Beating a low bar: Analysts had been expecting a relatively weak quarter for JPMorgan Chase beyond the legal costs because of a slowdown in mortgage lending and bond trading.

The bank took a hit in both of those businesses, which is a big reason that overall revenues fell to $23.9 billion in the quarter from $25.9 billion a year ago.

As interest rates rose this summer on fears that the Federal Reserve might cut its bond buying program, mortgage refinancing activity slowed down dramatically. That led to a drop in revenue and net interest income in JPMorgan Chase's mortgage business from a year ago.

CFO Marianne Lake said that mortgage activity had not rebounded despite the Fed's surprise decision to not taper its asset purchases just yet.

Still, JPMorgan Chase reported strong results from its investment banking division, as the bank generated more fees from underwriting new stock and bond offerings.

Related: JPMorgan's Dimon meets Holder for settlement talks

Legal woes multiply: The bank still faces many legal headaches. JPMorgan Chase is currently in negotiations with the Justice Department on a potential settlement for its sale of mortgage-backed securities ahead of the financial crisis. The Justice Department is seeking to levy a fine of at least $11 billion.

If successful, this would be one of the largest fines in history. Both Lake and Dimon declined to comment further on pending litigation.

But the bank noted that it is holding $23 billion in reserves for potential litigation expenses. In a footnote to its SEC filing, the bank said legal costs could be nearly $6 billion above that figure in a worst case scenario.

Lake said the "situation escalated" with regard to the DOJ discussions and noted that the size of potential settlements "have gone far beyond anything we reasonably expected."

Dimon has been lauded for keeping JPMorgan Chase profitable during the financial crisis and for rescuing Bear Stearns and Washington Mutual with the help of the government during the financial crisis. But he's now in unfamiliar territory. In addition to the government lawsuits, some shareholders are wondering if Dimon's reputation has now been tarnished.

Just last month, JPMorgan Chase agreed to pay $920 million in fines over last year's "London Whale" trading debacle, and $80 million more over allegedly unfair credit card billing practices.

In July, the bank agreed to pay $410 million to settle charges that it manipulated electricity prices in California and the Midwest. It is also facing scrutiny over its hiring practices in China and its alleged involvement in the Libor rate-fixing scandal.

Related: Default would be catastrophic for big banks

The new look of JPMorgan Chase: Dimon often reminds investors that JPMorgan Chase was a port during the storm of the financial crisis. But the bank now appears to be making a concerted effort to distance itself from errors that has led to the massive legal expenses and negative press.

To bolster its risk controls, JPMorgan Chase said it will spend an additional $1 billion in 2013 and add 5,000 employees dedicated to monitoring risks.

"This is a permanent investment. These costs will not go away," said Dimon.

Additionally, JPMorgan is "simplifying" its business by shedding several controversial units and clients. Among them: student lending, lending to the check cashing business, and its ownership of physical commodities, including electricity, aluminum and oil.

Banks came under scrutiny earlier this year for owning stakes in commodities businesses, after the New York Times ran an article alleging that Goldman Sachs's aluminum business was artificially pushing up prices.

Despite the legal concerns, the bank's stock is up nearly 20% in 2013. Bank stocks have been market leaders this year, and JPMorgan Chase is the first major financial firm to report its results.

Wells Fargo (WFC) released its third quarter earnings Friday morning as well. Earnings topped expectations, but the stock fell due to concerns about a drop in mortgage volume.

Bank of America (BAC), Citigroup (C), Goldman Sachs (GS) and Morgan Stanley (MS) will report next week.

CNNMoney's James O'Toole contributed to this report.