Royal Bank of Scotland beat expectations with a return to profit in the first quarter as bad debts continued to shrink, even as investment banking profits more than halved after a bumper start to last year.

Following in the footsteps of bailed-out British rival Lloyds , which announced an unexpected return to profit in the first quarter last week, part-nationalized RBS said impairments had continued to drop and margins rose from historically low levels in 2009.

The bank said it expected net interest margins to gradually improve over 2010.

But RBS, still nursing its wounds after it was caught in the maelstrom of the financial crisis, warned bad debt levels would remain high and could be volatile, particularly in the non-core portfolio that includes assets it is planning to sell.

Global recovery is helping impairments fall a little faster than we expected, though lumpy events may well interrupt that trend, Chief Executive Stephen Hester said.

RBS, 83 percent state-owned, said operating profit for the first three months totaled 713 million pounds ($1.10 billion) compared with a loss of 1.35 billion in the fourth quarter and a profit of 179 million a year ago.

Analysts had expected an operating loss.

After costs including 500 million pounds related to a government-backed insurance scheme for bad debts, the bank posted a pre-tax loss of 21 million pounds.

Impairment losses dropped to 2.68 billion pounds in the first three months compared to 3.1 billion in the fourth quarter last year and the bank said trends were favorable, confirming its prediction that bad debts peaked in 2009.

The bank's net interest margin improved to 1.92 percent, up 9 basis points from the fourth quarter.

Profits from its global banking and markets arm more than halved to 1.47 billion pounds from 3.47 billion a year ago, when unusually rampant capital markets lifted profits across the sector. The investment banking unit saw an operating profit of 871 million pounds in the fourth quarter of last year.

GBM was radically restructured 15 months ago and is the area with greatest people retention challenges, so we are pleased with progress in this important division, Hester said.

RBS said it was making good progress on restructuring and sales forced on it by European competition authorities, and said the sale of 318 branches and its card payment processing business WorldPay were on track.

Lloyds surprised the market last week with news it had returned to profit in the first quarter, earlier than expected, as losses on bad debts fall. It now expects to post both a full-year and a half-year profit.

($1=.6465 pounds)

(Reporting by Clara Ferreira-Marques and Steve Slater; Editing by Mike Nesbit)