Exterior of Rite Aid store A Rite Aid store in Buffalo, NY. (Photo: Wierzba Masonry)

DEERFIELD, IL—Walgreens Boots Alliance Inc. and Rite Aid have called off the merger that would have created a drugstore behemoth of about 18,000 locations. Instead, WBA said Thursday it would purchase 2,186 stores, three distribution centers and related inventory from Rite Aid for $5.175 billion in cash.

The agreement between WBA and Rite Aid calls for WBA to assume the related real estate leases and grants Rite Aid an option through May 2019 to become a member of WBA’s group purchasing organization, Walgreens Boots Alliance Development GmbH. WBA will also assume certain limited store-related liabilities as part of the new transaction.

Acquisition of the Rite Aid locations will be on a phased basis over a period of approximately six months. WBA intends to convert the acquired stores to the Walgreens brand over time.

WBA and Rite Aid first announced a merger agreement in October 2015, giving Rite Aid an enterprise value of $17.2 billion. This past December, the two companies announced an agreement to divest certain certain Rite Aid stores to Fred’s Inc. That agreement has been terminated as well, and WBA will pay Rite Aid a $325-million breakup fee in connection with the annulled merger.

“This new transaction extends our growth strategy and offers additional operational and financial benefits,” says Stefano Pessina, WBA’s executive vice chairman and CEO. “It will allow us to expand and optimize our retail pharmacy network in key markets in the US, including the Northeast, and provide customers and patients with greater access to convenient, affordable care.

Pessina adds that the new agreement with Rite Aid “addresses competitive concerns previously raised with respect to the prior transaction and will streamline and simplify the transition for customers, team members and other stakeholders.” The initial closing is expected to occur within the next six months.