Ending months of costly sparring, Walgreen (WAG) inked a multi-year pharmacy benefits network agreement on Thursday with Express Scripts (ESRX), sending the drugstore operator’s shares soaring double digits.

Walgreen, the No. 1 U.S. drugstore chain, had suffered from shrinking sales after its contract with pharmacy benefits manager Express Scripts retired at the end of last year.

The two sides revealed few details of the new deal, but said the contract spans multiple years and take effect on September 15.

“This agreement is good for our shareholders, our employees and the patients and communities we serve every day,” Walgreen CEO Greg Wasson said in a statement. “We look forward to once again filling prescriptions and offering our health and wellness services as part of the Express Scripts network."

It's clear the absence of the Express Scripts deal was hurting sales. For example, Walgreen estimated not being part of the Express Scripts network negatively impacted its prescription sales by 10.8 percentage points in May, contributing to a 5.8% slump in same-store sales that month.  

Shareholders cheered the new pact, bidding shares of Deerfield, Ill.-based Walgreen 12.3% higher to $34.78 in recent trading on Thursday. Shares of Express Scripts hit 52-week highs, recently trading up 2.12% to $58.92.

St. Louis-based Express Scripts manages over a billion prescriptions a year and has a network that now includes 64,000 pharmacies around the U.S.

“We are happy to include Walgreens in our broadest network of pharmacies and we are pleased to reach an agreement to do so,” said Express Scripts CEO George Paz.

Shares of drugstore rival CVS Caremark (CVS) retreated on the news, falling 3.98% to $46.51 in recent action.

Follow Matt Egan on Twitter @MattMEgan5