Toyota has agreed to buy an 8.7% stake in Japanese manufacturer Fuji Heavy Industries, the owner of Subaru, from General Motors.

Officials from both companies told the Associated Press the deal will make Toyota the top shareholder in the company.

The struggling automaker plans to sell its remaining 11.4% stake and dissolve its alliance with Fuji.