The logo of Toshiba Corp is seen behind cherry blossoms at the company's headquarters in Tokyo, Japan April 11, 2017. REUTERS/Toru Hanai

TOKYO (Reuters) - Japan’s Toshiba Corp said on Wednesday it has agreed to sell its prized semiconductor business to a group led by U.S. private equity firm Bain Capital LP, a key step in keeping the struggling Japanese conglomerate listed on the Tokyo exchange.

Toshiba said in a nighttime announcement through the exchange its board decided to sign a contract for the deal worth about 2 trillion yen ($18 billion), the latest and perhaps final twist in a deal that only hours earlier had seen the company leading toward an agreement with its U.S. joint venture partner Western Digital Corp.

The decision to sell the world’s No. 2 producer of NAND memory chips, first reported by Reuters on Wednesday, was made at a board meeting earlier in the day.

Toshiba said the agreement assumed the deal would weather legal challenges raised by Western Digital. A Western Digital spokeswoman said the company did not have an immediate comment.

(The story corrects to show the board decided to sign a contract, not that it had been signed)