Britain's two largest retail lenders have agreed to a massive shake-up of the banking sector that will see both sell hundreds of branches and key businesses to appease EU concerns over state aid and competition.

Part-nationalized Royal Bank of Scotland and Lloyds Banking Group ended months of uncertainty on Tuesday, with Lloyds announcing it would drop out of a government-backed insurance scheme for bad debts by raising 13.5 billion pounds ($22.08 billion) in the world's largest ever rights issue, as part of a 21 billion-pound capital raising plan.

The move leaves RBS, 70 percent state-owned, as the only bank joining the government's Asset Protection Scheme but RBS said it had secured more flexible terms than envisaged earlier this year that will allow it to exit the scheme within four years.

Both banks, however, were also hit by disposal orders to meet EU state aid rules, with RBS forced to sell chunks of its retail bank, RBS Insurance and to shrink its investment banking arm.

We do feel bruised by what we've had to go through, RBS's chief executive Stephen Hester told reporters on a conference call.

We feel that the job (of turning around RBS) has been made more difficult for us but we understand the conflicting pressures.

Our job has been made more difficult by some of the aspects of the EU settlement but nevertheless we believe it is a doable job, he added.

Shares in RBS were down 1.4 percent at 0845 GMT (3:45 a.m. EST) at 38p, well below the average price of 50.5p paid by the government for its stake in the bank. Lloyds was up 5.9 percent at 90p, also below the government's average entry price of 122.6p.

The European Union has effectively torn up the UK's initial rescue scheme for Lloyds/HBOS, with the aim of reducing dominant UK market positions, Keith Bowman, an analyst at Hargreaves Lansdown Stockbrokers. The news is potentially good for both UK consumers and rival banking groups, although more debatable for both Lloyds and RBS shareholders.

The UK government said the disposals deal announced on Tuesday would increase competition in retail banking, bringing at least three new banks onto Britain's high streets in the next four years.

The British Treasury said Lloyds and RBS would between them have to sell off businesses equating to 10 percent of the UK retail banking market. Only new entrants or small players in the UK market will be allowed to buy the assets, raising the key question of which buyers will step up.

Lloyds said it would sell 600 of its retail branches, with disposals including Lloyds TSB Scotland and Cheltenham & Gloucester mortgage business branches, as well as its Intelligent Finance and the TSB brand.

RBS -- facing tougher EU sanctions including punitive sales imposed as late as this week -- will be forced to sell NatWest branches in Scotland, RBS-branded branches in England and Wales, along with RBS Insurance, Global Merchant Services and RBS Sempra Commodities.

Both banks will have up to five years to make the sales.

LLOYDS DEAL

To avoid the APS, Lloyds said it would raise 21 billion pounds ($34.3 billion) via a 13.5 billion-pound rights issue and by swapping 7.5 billion pounds in existing debt into contingent capital, which will support the bank's capital requirements.

The move will allow Lloyds to avoid the fees associated with the scheme and will cap the government's stake at 43 percent -- while also helping the bank get a better deal with Brussels.

RBS said its participation in the insurance scheme would be under better terms, confirming an expected pay-as-you-go arrangement that will allow it to pay annually, rather than via a single upfront fee of 6.5 billion pounds, making it easier for the bank to exit it altogether within four years.

It will now pay 700 million pounds a year for the first three years of membership and 500 million pounds a year thereafter. Under the deal, the extent of any losses borne by the bank rather than the government will rise to 60 billion pounds from 42 billion pounds previously, making it unlikely the bank will dip into the APS fund.

In return for sidestepping or limiting the impact of the APS the banks also agreed not to pay discretionary cash bonuses in relation to 2009 performance to any staff earning above 39,000 pounds while executive members of both boards agreed to defer all bonuses payments due for 2009 until 2012.

On Lloyds, UBS and Merrill Lynch were joint advisers. Morgan Stanley and UBS were joint advisers for RBS.

See also (double-click inside brackets):

For a graph, see:

http://graphic.thomsonreuters.com/119/UK_BNKS1109.gif

($1=.6115 pounds)

(Writing by Paul Hoskins; Editing by Greg Mahlich)