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 earnings more than halved from its strong start to last year.

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

There are some grounds for optimism within the statement, notwithstanding the challenges facing the macro economic environment, Richard Hunter, head of UK Equities at stockbrokers Hargreaves Lansdown, said.

But news of an operating profit failed to cheer RBS shares, which have dropped more than 15 percent this week as worries intensify over a debt crisis in the euro zone. The stock was trading down 1.1 percent at 47.69 pence by 0824 GMT, back below the 50p average price paid by the government for its shares in the bank.

RBS has said its exposure to Greece is manageable and CEO Stephen Hester said on Friday his main concern was contagion.

We have always warned that the world does not spring effortlessly from despair to triumph and there will be aftershocks, Hester told reporters.

It's right that markets have an uncomfortable reminder that it is not plain sailing from here... and we have to live through that volatility until the economic balances around the world have been dealt with.

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

The bank, 83 percent state-owned, said operating profit for the first three months totaled 713 million pounds ($1.1 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.

The bank's net attributable loss shrank to 248 million pounds from 765 million in the fourth quarter.

BAD DEBTS IMPROVE

Impairments, which have driven losses at banks including RBS, dropped to 2.68 billion pounds in the first three months compared to 3.1 billion in the fourth quarter 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, boosted by its investment banking arm, and RBS said it expected margins to gradually improve over 2010.

Its global banking and markets arm's operating profit fell to 1.47 billion pounds from 3.47 billion a year ago, when unusually rampant capital markets lifted banks across the sector. The investment banking unit saw an operating profit of 871 million pounds in the fourth quarter of last year.

Hester said the unit was still particularly hard hit as the bank as whole felt the impact of damaging staff losses, though he said 2010 would be the last year in the damaging category.

Two nagging concerns for the bank remained its trouble spot, Irish unit Ulster Bank, where bad debt trends remain poor and recovery slow, and RBS Insurance, where 75 million pounds of bad weather costs again dragged the unit to a loss.

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. It expects to strike a deal on both within the current year.

(Editing by Mike Nesbit)

($1=.6465 pounds)