Shareholders of Rite Aid Corporation (NYSE:RAD) and Fred’s, Inc. (NASDAQ:FRED) are having a rough morning, following the news that drugstore chain Walgreens Boots Alliance Inc (NASDAQ:WBA) has terminated its merger agreement with Rite Aid and announced a new deal that instead has it buying nearly half of the smaller rival’s U.S. stores for $5.18 billion.

For scrapping the transaction, Walgreens will pay a $325 million termination fee to Rite Aid. It will pay Fred’s an additional $25 million following the termination of a related asset deal.

Shares of Rite Aid are currently falling nearly 24% to $2.99, while shares of Fred’s are down 22% to $9.63.

Rite Aid Chairman and CEO John Standley commented, “While we believe that pursuing the merger with WBA was the right thing to do for our investors and customers, this new agreement provides a clear path forward and positions Rite Aid as a strong, independent, multi-regional drugstore chain and pharmacy benefits manager with a compelling footprint in key markets […] The transaction offers clear solutions to assist us in addressing our pharmacy margin challenges and allows us to significantly reduce debt, resulting in a strong balance sheet and improved financial flexibility moving forward.”

Standley continued, “I would like to thank our entire Rite Aid team for their extraordinary efforts during this process and their tremendous focus on taking great care of our customers and patients. We have an outstanding team of associates and, with their continued support, we will work together to deliver a great customer experience, improve our business and deliver value to all of our stakeholders.”

Fred’s CEO Michael K. Bloom said, “While the acquisition of additional stores was an opportunity for growth, we always viewed it as a potential outcome that would accelerate our transformation, not define it. This is a disappointing outcome; however, the termination of the transaction has no impact on the Company’s transformation strategy or our ability to execute. We are as confident as ever that we have a strong team and the right strategy in place to drive long-term growth and profitability, and to enhance value for our shareholders. We are excited about what we have accomplished and are optimistic about the future.”

Mr. Bloom continued, “Our leadership team continues to deliver on its promise to optimize our business model and execute our healthcare strategy. We are capitalizing on opportunities to increase prescription comps in Retail Pharmacy, growing sales in Specialty Pharmacy and driving traffic into our front store. We also continue to optimize our store fleet, upgrade our talent, technology, supply chain and business processes. Our transformation is on track.”