Toshiba Corp. (TOSYY)  agreed to sell its memory chip unit for $17.7 billion to a consortium led by Bain Capital and Apple Inc. (AAPL)  , ending months of speculation and a multi-group bidding war that featured a legal effort to block the sale by joint-venture partner Western Digital Corp. (WDC)

Toshiba said it had entered into an share purchase agreement with Pangea, the acquisition vehicle, to transfer all the shares of Toshiba Memory Corp. for ¥2 trillion ($17.7 billion). Bain's consortium includes Hoya Corp. (HOCPY) , SK Hynix (HXSCL) , Apple, Kingston Technology Corp., Seagate Technology plc (STX) and Dell Technologies Capital.

Toshiba's shares were up 2.34% in Tokyo to close at ¥306, extending a 6.4% gain over the past three months.

Toshiba plans to reinvest ¥350.5 billion in Pangea to fund the transition. Bain plans to commit ¥212 billion, while Hoya has committed ¥27 billion ad SK Hynix plans to invest ¥395 billion.

The U.S. investors, including Apple, plan to commit ¥415.5 billion but will not acquire any common stock or voting rights. In addition, SK Hynix will be firewalled from accessing any proprietary information from the chip unit and will not be permitted to own more than 15% of the voting rights in Pangea for 10 years.

Toshiba expects the deal to close at the end of March 2018 but there are hurdles to overcome. The deal needs anti-trust and national security approval.

There is also the matter of ongoing litigation with Western Digital, which claims that it has the right to vote on the sale.

A signed agreement is a major step in the much-needed sale of Toshiba's valuable chip unit. The troubled Japanese conglomerate declared July 13 that it had signed a "non-binding memorandum of understanding," with Bain Capital "memorializing the parties' intent to negotiate" the sale of Toshiba's memory chip unit. But the company said it was opening to talking to other buyers.

Toshiba needs to sell the memory unit quickly to cover a record ¥950 billion net loss, and potential further liabilities, resulting from the collapse of its U.S. nuclear energy division Westinghouse Electric. Without new cash it faces delisting from the Tokyo exchange, a move that could lead to a wider bankruptcy of the business.

Watch: Could Your iPhone X be Delayed?

More of What's Trending on TheStreet:

More from Investing

UnitedHealth Could Strike Deal for Tenet's Conifer Subsidiary: Reports

UnitedHealth Could Strike Deal for Tenet's Conifer Subsidiary: Reports

CEO Report Card: Domino's Richard J. Allison Jr.

CEO Report Card: Domino's Richard J. Allison Jr.

One Chart Will Make You Even More Pumped Up to Buy Tech Stocks

One Chart Will Make You Even More Pumped Up to Buy Tech Stocks

Google Shares Shrug Off $5 Billion EU Fine Against Alphabet

Google Shares Shrug Off $5 Billion EU Fine Against Alphabet

Jim Cramer's Biggest Moments From Delivering Alpha

Jim Cramer's Biggest Moments From Delivering Alpha