JP Morgan reported net income of $5.6bn (£3.5bn, €4.4bn) in the third quarter having managed to put a raft of legal costs behind it, compared with a year-earlier loss of $380m.

The bank's results, which were leaked early onto a website, showed that on a per-share basis, the bank's profit was $1.36 a share in the three months ended 30 September, compared with a loss of 17 cents in the same period last year.

Analysts polled by Thomson Reuters had expected earnings of $1.38 a share.

Last year's Q3 loss was the only deficit reported under the tenure of chief executive officer Jamie Dimon.

JP Morgan's legal expenses reached an eye-watering $9.3bn during its loss-making third quarter of 2013. For the three months to September these amounted to $1.1bn, up from $700m in the previous quarter.

Dimon said in a statement: "Despite challenges, we have continued to deliver strong underlying performance, maintain our fortress balance sheet and liquidity, simplify the business and adapt to regulatory changes."

Revenue for the quarter rose to $25.2bn, an increase of 5.4%. The revenue figures for a year ago were $23.88bn.

Revenue from fixed-income, currency and commodity trading rose 2.1% to $3.51bn in the quarter, compared with a year earlier.

Last year the bank was hit with an after-tax expense of $7.2bn to settle allegations related to mortgage instruments before the financial crisis.

The bank has also recently divulged the extent of a cyber-security breach: hackers had obtained contact information of 76 million households and 7 million small businesses.

Last week, Dimon, who was making his first public appearance since getting treated for throat cancer, said JP Morgan will probably double its $250m annual cyber-security budget within five years.