JPMorgan Chase & Co posted a higher-than-expected jump in second-quarter profit as it wrote off fewer bad mortgages and credit card loans.

The second-largest U.S. bank managed to make new loans faster than customers paid off existing ones during the quarter, a reversal from the first quarter and a bright spot for a sector long plagued by weak loan demand.

JPMorgan's revenue rose and it added staff, and its shares were up 2.75 percent in afternoon trading.

But the bank still faces stiff headwinds, including big expenses from mortgages as the effects of the housing crisis linger.

Foreclosures could take another 12 to 18 months to start declining, Chief Executive Jamie Dimon said on a conference call with reporters.

JPMorgan's revenue growth is a sign that things are getting better. They're just not getting better quickly, said Ralph Cole, portfolio manager at Ferguson Wellman Capital Management in Portland, Oregon. Ferguson Wellman owns JPMorgan shares.

Although loans at the end of the second quarter were up from the end of the first quarter, average loans outstanding during the latest quarter declined, signaling that even if loan demand is improving, growth is uneven.

JPMorgan is the first major U.S. bank to post quarterly results, and its performance gives hints about how other banks fared in the period.

BOND TRADING

Bond trading revenue fell 18 percent from the first quarter, but the decline was less than some investors had feared. Shares of investment banks Goldman Sachs Group Inc and Morgan Stanley initially rose on hopes that JPMorgan's trading results bode well for the sector, but turned negative later in the day.

JPMorgan earned $5.43 billion, or $1.27 a share, in the second quarter, beating the average Wall Street estimate by 6 cents a share, according to Thomson Reuters I/B/E/S.

The results were up from year-earlier earnings of $4.8 billion, or $1.09 a share.

The bank benefited from not having to pay a British tax on bonuses. In the year-earlier period, that tax reduced profits by $550 million, or 14 cents a share.

JPMorgan made more loans during the quarter, net of customer loan repayments. Its loan book grew to $689.74 billion at the end of the quarter from $686 billion at the end of March as increased business lending offset a 2 percent decline in consumer lending.

The bank also gathered more deposits during the quarter; deposits surged by 5 percent from the first quarter to $1.05 trillion. Chief Financial Officer Douglas Braunstein said mid-sized companies delivered much of the money.

Deposits could support more loans in the future, if there is enough demand.

Shrinking loan books and low interest rates since 2008 have made it difficult for banks to post profits, or increase them. A large part of earnings over the past year has come from setting aside less money to cover bad loans, or dipping into funds previously set aside.

Many analysts are hoping banks will start to post loan growth in the coming quarters, which would be a sign of sustainable increases in profits.

Dimon, who is famously blunt, seemed optimistic about the outlook for profits. He said the bank will build capital levels in the coming months, and criticized regulators for not allowing it to return those funds to shareholders faster.

God knows why we have to hold all that capital, Dimon said, adding that banks' capital ratios are going to drive up so fast people are going to be surprised.

Banks returned billions of dollars of capital to investors in 2007 and 2008, even as large clouds gathered over the mortgage market.

JPMorgan reduced the expense it recorded for credit costs to $1.81 billion in the second quarter from $3.36 billion a year earlier. However, that was up from $1.17 billion in the 2011 first quarter.

JPMorgan shares were up 2.8 percent to $40.73 in afternoon trading following the results.

TAKING TIME WITH MORTGAGES

Dimon said in the earnings announcement that mortgage costs were down slightly, but cautioned that the housing market was still working through difficulties.

Unfortunately, it will take some time to resolve these issues and it is possible we will incur additional costs along the way, he added.

In a sign of the lingering difficulties that banks are facing with home loans, JPMorgan said it expects to have to repurchase $3.6 billion of mortgages that it packaged into bonds. Such repurchases are usually because a bank failed to properly collect payments on the mortgages, or should never have sold them to investors in the first place.

JPMorgan said it added $1.3 billion to its litigation reserves, mainly for mortgage-related matters. It also continued to add to its loan reserves for losses on mortgages.

It is possible we are very over-reserved in mortgage land, Dimon said in a conference call with analysts.

He expects to win a legal battle with the Federal Deposit Insurance Corp over liabilities left from busted lender Washington Mutual, pieces of which JPMorgan bought in a government-arranged deal during the financial crisis.

Credit card delinquencies are improving so quickly that the bank drew down its reserves for losses on those balances, adding 15 cents a share to second-quarter profit.

The charge-off rate for uncollectible card debt will be down to about 4.5 percent this quarter, nearly a year earlier than previously expected, said Chief Financial Officer Douglas Braunstein. The improvement echoed comments Wednesday from card lender Capital One Financial Corp.

JPMorgan has been hiring people to work out its problems with mortgages, still the biggest drag on its business. The bank said it hired 10,000 people in the second quarter. Employment at the bank reached 250,095 people at the end of June.

At the same time, compensation expenses slid in the last three months as pay for employees in the investment bank declined 22 percent from the first quarter when trading revenue shrank. Compensation costs at the investment bank fell by $730 million to 35 percent of revenues, down from 40 percent in the first quarter.

The decline in pay at the investment bank shows Dimon's strength at keeping costs in line with JPMorgan's business volumes, said Credit Suisse analyst Moshe Orenbuch.

When revenues are down, JPM manages to bring down their costs faster than everyone else. That really did cushion some of the earnings decline, said Orenbuch.

(Reporting by David Henry and Dan Wilchins, additional reporting by Maria Aspan, Joe Rauch and Knut Engelmann; editing by John Wallace)