Britain's two largest retail lenders are to get another 31 billion pounds from the government and have agreed to sell hundreds of branches and key businesses to appease EU competition concerns over state aid.

The deal announced on Tuesday paves the way for Britain to begin reducing its holdings in Royal Bank of Scotland and Lloyds Banking Group , a potentially critical source of funds as the country struggles with a ballooning budget deficit.

RBS and Lloyds ended months of uncertainty, with Lloyds announcing that it would drop out of a government 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 under more flexible terms than expected earlier this year, which RBS said will allow it to leave the scheme within four years.

Both banks, however, also agreed to disposals to meet EU state aid rules, with RBS particularly hit, selling chunks of its retail bank under the revived brand Williams & Glyn, its RBS Insurance arm and shrinking its investment bank.

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

Our job (of turning around RBS) 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 4.8 percent at 1100 GMT at 36.8p, well below the average price of 50.5p paid by the government for its stake in the bank. Lloyds, whose takeover of beleaguered rival HBOS was backed by the state, was up 1.3 percent at 86.2p, also below the government's entry price of 122.6p.

The news is potentially good for both UK consumers and rival banking groups, although more debatable for both Lloyds and RBS shareholders, Keith Bowman, an analyst at Hargreaves Lansdown Stockbrokers.

The UK government, which will inject 25.5 billion pounds into RBS and pay Lloyds a net 5.7 billion pounds as a shareholder in the rights issue, said the disposals would shake up competition in retail banking, bringing at least three new banks to Britain's high streets over the next four years.

Lloyds and RBS will 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 market will be allowed to bid, raising the key question of which buyers will step up.

Lloyds, which avoided harsher penalties by staying out of the APS, said it would sell 600 of its retail branches, with disposals including Lloyds TSB Scotland, Cheltenham & Gloucester branches, as well as its Intelligent Finance and the TSB brand.

To address EU concerns, it will also face a dividend ban for two years and a prohibition on acquisitions for up to four years.

RBS -- whose 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, Britain's largest car insurer. It will also sell Global Merchant Services and RBS Sempra Commodities.

RBS said it expected buyer interest and was considering an initial public offering for RBS Insurance, which it initially put on the block in 2008, but pulled earlier this year.

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

LLOYDS DEAL

To sidestep the APS Lloyds confirmed market expectations it would raise 21 billion pounds via a discounted rights issue and by swapping 7.5 billion pounds in existing debt into contingent capital, which will support its capital requirements.

The move will allow Lloyds to avoid the fees associated with the costly scheme as the economy improves and will cap the government's stake at 43 percent. However, Lloyds said it will pay a 2.5 billion pound break fee to avoid the APS.

The fully underwritten 13.5 billion-pound rights issue, the largest since HSBC's cash call earlier this year, will be priced on Nov 24 at the higher of either 15p or a 38-42 percent discount to the ex-rights price.

Lloyds said it had received backing from shareholders and bond investors, but the response on Tuesday was mixed.

This deal does not look especially attractive ... They can't pay a dividend until 2012 at least and we still have all the secondary issuance to come, one top ten investor said. I find myself very underwhelmed.

But another top 10 investor added: The issue will go through successfully. The deal is done effectively.

PAY-AS-YOU-GO INSURANCE

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 6.5 billion pounds, making it easier for the bank to exit it altogether within four years, subject to a fee.

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 highly unlikely the bank will dip into the APS fund.

RBS will also get a contingent capital commitment from the government of 8 billion pounds, to be drawn on if the bank's core Tier 1 ratio falls below 5 percent.

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.

RBS said this would make its task of recruiting and retaining staff even tougher as it overhauls the bank.

The two banks will also be forced to stick to their commitments to lend business and homeowners 39 billion pounds.

On Lloyds, UBS and Merrill Lynch were joint advisers. Morgan Stanley and UBS were joint advisers for RBS. Credit Suisse and Deutsche Bank advised the Treasury.

For a graph, see:

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

($1=.6115 pounds)

(Additional reporting by Paul Hoskins, Myles Neligan, Raji Menon; Editing by Greg Mahlich)