LONDON (Reuters) - Royal Bank of Scotland (>> Royal Bank of Scotland Group plc) swung to a far better than expected first-quarter profit of 259 million pounds, sending its shares up as much as 4 percent as the lender showed signs of progress in a decade-long turnaround.

RBS's first quarterly profit since September 2015 had been expected, but the amount exceeded the 50 million pounds forecast average of analysts' estimates compiled by the bank.

Chief Executive Ross McEwan has said 2017 will probably be the final year RBS makes a loss, as it moves nearer to closing the darkest chapter in its 290-year history.

The bank has racked up more than 58 billion pounds in losses since its 45.5 billion pound bailout, the biggest for a European bank, at the height of the 2008-2009 financial crisis.

RBS shares lost some of their early gains on Friday and were up 2.3 percent by 0800 GMT, the second best performer in the STOXX European Banks index <.SX7P>, which dipped 0.3 percent.

The goal of making a profit in 2018 depends on resolving RBS's two biggest remaining headaches: its talks with the U.S. Justice Department on mortgage mis-selling, and with the European Union on the bank's state aid requirements.

RBS stands accused like many peers of mis-selling mortgage securities in the build-up to the 2008 financial crisis, and is expected to settle with U.S. authorities rather than fight the case like rival Barclays (>> Barclays PLC).

"We have nothing more to say on any engagement with the Department of Justice," McEwan told reporters on the call.

In January RBS set aside a further 3.1 billion pound provision as it prepares to settle the claims, which some analysts have said could end up costing it as much as 9 billion pounds in total.

Another big headache is an obligation RBS had under European state aid demands, whereby in recompense for receiving its bailout the bank would have to sell its Williams & Glyn unit.

RBS said in February it had found a potential escape from that seven-year process, which had been fraught with rising costs and complexity. Instead the government is applying to the European Commission to approve a new plan whereby RBS will instead put in place measures to boost the competitiveness of smaller British bank peers.

The European Commission is investigating the proposals.

This month British finance minister Philip Hammond said explicitly for the first time that the government is prepared to sell its remaining more than 70 percent stake in RBS at a loss.

Britain paid 45 billion pounds to buy the RBS stake during the financial crisis, but unlike its similarly bailed-out peer Lloyds Banking Group (>> Lloyds Banking Group PLC), RBS has been unable to return to profit.

Britain's government budget watchdog said in March that the government was sitting on a 29 billion pound paper loss from RBS, in contrast to modest profits on bail-outs of Lloyds and other financial institutions.

(Reporting By Lawrence White, editing by Huw Jones and Susan Thomas)

By Lawrence White