DUBLIN (Reuters) - U.S. drugmaker Perrigo (>> Perrigo Company) agreed to buy Elan (>> Elan Corporation, plc) for $8.6 billion in a deal that will hand it tax savings from being domiciled in Ireland and royalties from a blockbuster multiple sclerosis treatment.

The deal, agreed on Monday, ends a bitter takeover battle in which Elan rejected three lower bids from U.S. investment firm Royalty Pharma amid injunctions, court hearings and a war of words before putting itself up for sale last month.

Michigan-based Perrigo, which makes over-the-counter pharmaceuticals for the in-store brand market and has a market value of some $12 billion, will pay $6.25 per share in cash plus $10.25 per share in stock, a premium of about 10.5 percent over Elan's closing price on Friday.

Elan shares rose 3.8 percent on Monday to $15.5, close to a bid that analysts expect will be snapped up by shareholders who rejected Royalty's successive overtures. Perrigo shares dropped 6.7 percent to $125.3

"Elan has uncovered an excellent offer for its shareholders, substantially ahead of the level Royalty Pharma could achieve," Berenberg Biotech analysts said in a note to clients.

For Elan and Chief Executive Kelly Martin, who took over the firm in 2003 when its share price had sunk to $2, the Perrigo deal is vindication for rejecting Royalty's advances.

Martin, a low-key former Merrill Lynch banker, took a series of verbal attacks in a four-month saga that frequently turned ugly.

In an open letter to the Elan board last month, Royalty predicted that Elan was embarking on a lengthy and likely fruitless effort to find a buyer willing to better its offer.

Royalty's final bid was $13 in cash per share as well as a "contingent value right" that could have added a further $2.50 per share if Elan's blockbuster multiple sclerosis drug Tysabri hit certain sales milestones.

According to Deutsche Bank analysts, Perrigo's offer is a significant premium to their $12 per share valuation of Elan, reflecting the tax advantage, and worth about a fifth more than their calculation of the Royalty bid.

TAX ADVANTAGE

Reuters reported exclusively last week that Perrigo and New York-based Forest Laboratories Inc (>> Forest Laboratories, Inc.) were preparing to bid.

Elan is especially appealing for companies like Perrigo that can easily move their headquarters abroad because of the very low 12.5 percent corporate tax rate in Ireland, compared with 35 percent in the United States.

Fellow generic drugmaker Actavis' (>> Actavis Inc) $5 billion acquisition of Dublin-based Warner Chilcott (>> Warner Chilcott Plc) in May allowed it lower its tax rate to 17 percent from 28 percent.

Hundreds of U.S. companies have subsidiaries in Ireland for the same purpose. That practice prompted international criticism after the U.S. Senate revealed that technology giant Apple (>> Apple Inc.) paid little or no tax on tens of billions of dollars in profits channeled through the country.

The Elan deal buys Perrigo a full tax domicile in Ireland, bringing the bulk of its income under the Irish tax regime. It will use $4.35 billion in bridge financing from Barclays and HSBC plus cash to fund the deal, which also brings it Elan's $1.9 billion cash pile.

Perrigo Chief Executive Joe Papa said the acquisition would cut its effective tax rate to 17 percent in the first 12 to 18 months from around 30 percent now. Chief Financial Officer Judy Brown told an analyst call that it may go even lower over time.

"We think it's financially compelling and when you put it together with an Irish domicile that has operational tax synergies, we think it's a really compelling story," Papa told Reuters in a telephone interview.

The Perrigo boss, for whom Elan is the largest of more than a dozen deals he has led since taking over in 2006, said the company remained committed to the United States where it employs over half of its 9,000 workers. It will remain listed in New York and Tel Aviv , he said.

Papa said Ireland would give Perrigo a gateway into the rest of Europe and saw the Tysabri royalty, worth of up to 25 percent on future sales, as a means to fund future opportunities.

Elan sold its 50 percent interest in Tysabri to U.S. partner Biogen Idec (>> Biogen Idec Inc) in February for $3.25 billion but retained royalties in the drug whose sales rose to $1.6 billion in 2012.

Elan, founded as a private company in 1969, also drew initial interest from Allergan Inc (>> Allergan, Inc.), Mylan International (>> Mylan Inc.) and Endo HealthSolutions Inc (>> Endo Health Solutions Inc), several people familiar with the situation have said.

Barclays advised Perrigo on the deal, while Citigroup Global Markets, Davy and Davy Corporate Finance, Morgan Stanley & Co. International and Ondra LLP acted for Elan.

($1 = 0.7539 euros)

(Editing by Tom Pfeiffer and Erica Billingham)

By Padraic Halpin and Sam Cage