(Reuters) — Tesla and Elon Musk have agreed to pay $20 million each to financial regulators and the billionaire will step down as the company’s chairman but remain as chief executive, under a settlement that caps a tumultuous two months for the car-maker.

The securities fraud agreement, announced by the Securities and Exchange Commission (SEC) on Saturday, will come as a relief to investors, who had worried that a lengthy legal fight would only further hurt the loss-making electric car company.

The SEC said Musk, 47, misled investors with tweets on Aug. 7 in which he said he was considering taking Tesla private and had secured funding.

The regulator had alleged in a lawsuit on Thursday that the tweets had no basis in fact, and said the market chaos that ensued hurt investors.

The SEC charges against Musk on Friday shaved about $7 billion off high-flying Tesla, knocking its market value to $45.2 billion on Friday, below General Motors’s $47.5 billion.

In the settlement, the agency pulled back from its demand that Musk, who is synonymous with the Tesla brand, be barred from running Tesla, a sanction that many investors said would be disastrous.

“I think this is the best possible outcome for everyone involved” said Ivan Feinseth of Tigress Financial Partners, who rates Tesla ‘neutral’, who added the SEC’s penalty was only a slap on the wrist for Musk.

“The fact that he can remain CEO is very important for the company.”

Neither Musk nor Tesla admitted or denied the SEC’s findings as part of the settlement. Tesla and Musk did not immediately respond to requests for comment.

Investors and corporate governance experts said on Saturday that the agreement could strengthen Tesla, which has been bruised by Musk’s recent volatile behavior. He was filmed smoking marijuana and wielding a sword on a webcast this month just hours before Tesla said its recently-appointed accounting chief would leave.

The entrepreneur had been directly involved in almost every detail of Tesla’s product design and technology strategy, and drove the company’s employees to extraordinary achievements – much as another Silicon Valley chief executive, Steve Jobs, did at Apple Inc.

Musk is now required to step down as chairman of Tesla within 45 days, and he is not permitted to be re-elected to the post for three years. Tesla is required to appoint two new independent directors to its board, a move Feinseth should strengthen the company.

The SEC charged Tesla with failing to have required disclosure controls and procedures for Musk’s tweets. The SEC said the company had no way to determine if his tweets contained information that must be disclosed in corporate filings, or if they contained complete and accurate information.

Musk walked away at the last minute from an earlier settlement with the SEC that would have required him to give up key leadership roles at the company for two years and pay a nominal fine, according to media reports on Friday.

Investors said on Friday that it has been a big mistake for Musk to turn down that settlement, especially at a time when the company has been pushing hard to meet production targets.

The settlement tasks the Tesla board, which many critics have accused of failing to rein in Musk, with the tricky challenge of finding an independent chairman who is able to work closely with the often emotional and unpredictable chief executive.

Musk, who has often turned to Twitter to promote Tesla and confront critics, said on Thursday that the SEC’s actions were unjustified. Tesla shares jumped after his Aug. 7 tweets, a blow to short-sellers betting on the stock’s decline.

As CEO, Musk had gained legions of fans for his bold approach to business and technology. He used his Twitter account to promote the achievements of Tesla, his rocket launch company SpaceX, and other projects such as his tunnel venture, the Boring Co, to his nearly 23 million followers.