In a surprise move, Rite Aid Corp. and Albertsons Cos. called off their planned $24 billion merger on the eve of a shareholder vote in the face of mounting protests from investors.

Some of Rite Aid’s biggest shareholders had planned to vote against the pharmacy’s planned merger with privately held grocer Albertsons, unconvinced by the companies’ argument that a deal was necessary to fend off competition from Amazon.com Inc. and others.

Investors who opposed the deal, valued at $24 billion including debt when it was announced in February, said it undervalued Rite Aid’s retail business and its prescription-drug benefit service. They and two major shareholder proxy advisory firms that criticized the deal in recent weeks also questioned the ties between top executives on both sides.

The retailers each said their mutual decision to call it quits was made despite their belief in the deal’s rationale. Albertsons said it disagreed with investors and proxy-advisory firms that felt it had undervalued its offer for Rite Aid, which has a market-capitalization of under $2 billion. Albertsons board declined to change the terms of the merger, the retailer said.

Rite Aid’s stock rose more than 2% in after-hours trading. Most of Rite Aid’s largest institutional shareholders planned to oppose the deal, people familiar with the matter said, and some smaller shareholders also had concerns. Some who own Rite Aid shares said privately they supported the deal because they didn’t see the retailer thriving as a stand-alone company.