The financial crisis has finally caught up with JPMorgan Chase (JPM 1.44%). This morning, the nation's largest bank by assets reported a surprising loss for the three months ended September 30. It was the first quarterly loss under chief executive officer Jamie Dimon's watch and the first time that the bank hadn't made money in nearly a decade.

The impetus for the disappointing performance stems from billions of dollars the bank set aside to cover future litigation costs. Over the last few months, JPMorgan has found itself in the legal and regulatory crosshairs for a multitude of alleged violations.

The Securities and Exchange Commission is investigating whether it gave jobs to the children of high-ranking government officials in China in order to woo business. The Justice Department is looking into the quality of mortgage-backed securities it sold in the lead-up to the crisis. It recently settled regulatory actions related to last year's London Whale scandal. And the list goes on and on.

In anticipation of future payouts, JPMorgan recorded a $9.2 billion expense in order to build its litigation reserves.

"We continuously evaluate our legal reserves, but in this highly charged and unpredictable environment, with escalating demands and penalties from multiple government agencies, we thought it was prudent to significantly strengthen them," said Dimon. "While we expect our litigation costs should abate and normalize over time, they may continue to be volatile over the next several quarters."

Not unlike Bank of America (BAC 1.70%), which inherited the lion's share of its legal and regulatory woes via its acquisition of Countrywide Financial, JPMorgan is now reaping what it sowed through its crisis-era takeovers of Bear Stearns and Washington Mutual.

The one difference being that JPMorgan's moves were encouraged, if not underwritten, by and at the behest of the federal government. The resulting frustration came through loud and clear in the bank's earnings release.

According to Dimon (emphasis added), "The Board continues to seek a fair and reasonable settlement with the government on mortgage-related issues -- and one that recognizes the extraordinary circumstances of the Bear Stearns and Washington Mutual transactions, which were undertaken at the request or encouragement of the U.S. Government."

Litigation expenses aside, JPMorgan earned $5.8 billion, or $1.42 per share, which handily exceeded analysts' expectations of $4.65 billion, or $1.21 per share.

Every indication suggests its core businesses are performing well. Deposits were up by 10% in its consumer and community banking division. Its corporate and investment bank maintained its leadership position in global investment banking fees. And the bank's asset management division recorded its 18th consecutive quarter of positive net long-term client flows.

In addition, serving as perhaps a harbinger of things to come from the rest of the industry, its mortgage origination volume held up better than expected despite the sharp decline in refinance activity. Last month, chief financial officer Marianne Lake predicted that its home loan volume could drop by as much as 40%. But today, we learned that it declined by a much more reasonable 18%.

However, the same cannot be said for Wells Fargo (WFC -0.26%), which reported today that its third-quarter mortgage origination volume came in at $80 billion. The performance broke Wells Fargo's record streak of seven consecutive quarters in which it underwrote more than $100 billion in home loans.

At the end of the day, whether you love JPMorgan or hate it, there's little doubt that it's one of the most successful financial institutions in the world. And with a staggering $23 billion in reserves to protect against future legal costs and settlements, it's hard to imagine that this quarter is anything but a blip on the megabank's otherwise profitable radar screen.

At the time of writing, shares of the bank are trading up by more than 1%.