Shares of Rite Aid (RAD) - Get Report and Fred's (FRED)  are up sharply this week after the companies, and Walgreens (WBA) - Get Report  , announced an agreement to sell 865 stores to Fred's for $950 million in cash. The sale to Fred's is meant to win Federal Trade Commission approval for Walgreens' plan to acquire Rite Aid, a $9.5 billion merger announced in October 2015.

Although Fred's had been considered to be possible buyer for some of the stores Walgreens and Rite Aid would have to spin off, that Walgreens plans for it to be the sole buyer of so many stores caught the market off guard. Shortly after noon, Rite Aid shares hit a high of $8.69 Tuesday, about 5.5% above Monday's $8.17 close. Fred's closed at $20.19, up more than 80% from Monday's $11.15 close. Shares ticked down slightly Wednesday morning.

The spinoff would transform Fred's from a regionally focused drug store and general retailer into the country's third-largest drugstore chain behind Walgreens and CVS. Headquartered in Memphis, Tenn., Fred's was founded in Coldwater, Miss., in 1947 and operates over 650 stores, mostly in rural areas and mid-sized towns in the Southeast. Rite Aid stores to be spun off would be located primarily in the eastern and western U.S.

Although the stores to be sold were not identified, most of the Rite Aid and Walgreens store overlaps raising competitive concern are believed to be in heavily populated urban and suburban areas.

Fred's CEO Michael Bloom said the merger will be "a transformative event for Fred's Pharmacy that will accelerate our healthcare growth strategy through our acquisition of 865 new stores located in highly attractive markets."

Approving the spinoff to Fred's, whose shares had dropped steadily from $15.89 on July 29 to a yearly low of $8.18 on Nov. 4 before speculation about it possibly buying stores from Rite Aid began pushing its shares up, would be a gamble for the FTC. Fred's has been struggling and the commission is still smarting from the debacle that resulted when the agency allowed Albertson's LLC to sell 146 stores to Haggen LLC, a small chain in the Pacific Northwest, as a condition of antitrust approval for Albertson's acquisition of Safeway. Haggen soon filed for bankruptcy amid disputes with its private equity backers.

Editors' note: This article was originally published by The Deal, a sister publication of TheStreet that offers sophisticated insight and analysis on all types of deals, from inception to integration. Click here for a free trial.

Like Haggen, Fred's can't pull off an expansion of this size on its own and the FTC, headed by current chairwoman Edith Ramirez (pictured), will need to be convinced it has financial backers willing to see the transformation through.  FTC officials declined to comment.

Walgreens spokesman Michael Polzin said Fred's is an experienced drug store operator and is capable of handling the transition the spinoff would require.

Fred's in an SEC filing Tuesday said it has a $1.05 billion asset-based lending commitment from Bank of America, Merrill Lynch and Regions Bank as well as a $600 million term loan from Merrill Lynch, TPG Specialty Lending, Crystal Financial, Gordon Brothers Finance, Pathlight Capital, Tennenbaum Capital Partners, and Great
American Capital Partners.

Walgreens has also agreed to provide Fred's with transitional services for up to 30 months after the deal closes.

"The sale of 865 Rite Aid stores to Fred's Pharmacy increases the likelihood of FTC approval for the WBA-RAD merger," said Jim Cramer, TheStreet's founder and manager of the Action Alerts PLUS portfolio, which owns WBA.

Credit Suisse analyst Robert Willoughby agreed. "We view Fred's as a credible operator and see little reason why the transaction would prevent WBA from closing its acquisition of RAD next year," he wrote in a client alert Tuesday.

However Walgreens is not obligated to defend the divestiture to Fred's in court if the FTC staff rejects the spinoff. According to Fred's securities filing, Walgreens may terminate the sale to Fred's if FTC staff informs Walgreens in writing that the director of the FTC Competition Bureau recommends against accepting Fred's as purchaser of the divestiture assets. Any party to the deal may terminate the agreement if is not closed by June 30, 2017.