CVS Caremark Corp and Walgreen Co ended an 11-day standoff over reimbursements for drug prescriptions, saving a relationship worth billions of dollars and lifting shares of the two biggest U.S. drugstore chains.

Caremark members would continue to be able to have their prescriptions filled at Walgreen's pharmacies, the companies said in a statement on Friday. They did not disclose the exact terms of the agreement, but said it was a multi-year deal.

Walgreen shares were up 3.8 percent at $30.37 in late morning trading while CVS shares rose 3.3 percent to $32.89. Shares in rival pharmacy benefit management companies Medco Health Solutions and Express Scripts , who were likely to benefit if the dispute continued, fell more than 1 percent.

Walgreen, the No. 1 U.S. drugstore chain, said early last week that it would end its arrangement to fill prescriptions for millions of CVS Caremark drug plan members. It cited CVS's efforts to divert customers to its own pharmacies and inadequate reimbursement rates.

CVS said two days later that it would drop Walgreen from its network by July 9.

Analysts said the dispute was jeopardizing billions of dollars in sales for each chain, and predicted that the companies would resolve the problem quickly.

They had to reach a deal because there was a lot of risk to both the companies, said Lazard Capital Markets analyst Tom Gallucci.

S&P Equity Research analyst Joseph Agnese raised his rating on CVS shares to strong buy from buy, saying that the quick resolution of the dispute prevented damage to CVS' ability to line up new PBM business.

CVS's pharmacy benefits management business administers prescription drug benefits for employers and health plans. It also operates a large mail-order pharmacy.

BATTLE OVER REIMBURSEMENTS

Walgreen's arrangement with CVS's Caremark unit accounts for about 7 percent of sales, but analysts said Walgreen was willing to risk severing that relationship to send a larger message out to other PBMs that it would fight a trend to shrink reimbursements.

CVS was eager to show investors that its $27 billion purchase in 2007 of Caremark and its PBM business was a good deal, after losing $4.8 billion worth of contracts last year.

CVS could ill afford the disruption its standoff with Walgreen was creating as its campaign to sell its plans to large employers was peaking, analysts had said.

Walgreen holds great sway in the PBM business in part because it fills about one in five U.S. drug prescriptions.

Walgreen operates about 7,500 stores out of the 64,000 pharmacies served by Caremark's network.

That leverage probably allowed Walgreen to squeeze out some concessions on reimbursement rates, an analyst said.

My best guess would be that Walgreen got some higher reimbursement rates that could eventually lead to higher margins for them, said Morningstar analyst Matthew Coffina.

(Additional reporting by Nivedita Bhattacharjee; Editing by Lisa Von Ahn, Robert MacMillan and Gunna Dickson)