Walgreens Boots Alliance has announced a new Rite Aid deal, effectively ending its nearly two-year quest to acquire the Camp Hill, Pa.-based drug store chain. The divestiture agreement with Fred’s Pharmacy, whereby Fred’s would buy 865 stores, is also terminated.

The move comes after Walgreens has struggled to win approval of the deal from the Federal Trade Commission. Under the new agreement, Walgreens will acquire 2,186 of Rite Aid’s 4,523 stores for $5.175 billion in cash. Also, Rite Aid will receive a $325 million termination fee.

“This new transaction extends our growth strategy and offers additional operational and financial benefits,” Stefano Pessina, executive vice chairman and CEO of Walgreens Boots Alliance, said. “It will allow us to expand and optimize our retail pharmacy network in key markets in the U.S., including the Northeast, and provide customers and patients with…