JPMorgan Chase & Co posted higher-than-expected quarterly profit as it wrote off fewer bad mortgages and credit card loans.

JPMorgan, the first big U.S. bank to report second-quarter results, said it earned $5.4 billion, or $1.27 a share. Wall Street analysts, on average, had expected $1.21 per share, according to Thomson Reuters I/B/E/S.

The results compared with year-ago earnings of $4.8 billion, or $1.09 a share.

Chief Executive Jamie Dimon said in the earnings announcement that mortgage costs were down slightly. Unfortunately, it will take some time to resolve these issues and it is possible we will incur additional costs along the way, he added.

This quarter the bank did not have to pay a UK tax on bonuses. In the year-earlier period, the tax reduced profits by $550 million, or 14 cents a share.

JPMorgan shares rose 2 percent in premarket trading following the results. Stock futures briefly edged higher, then fell back.

(Reporting by David Henry; editing by John Wallace)