The S.E.C. announced the deal two days after it sued Mr. Musk in federal court for misleading investors over his post on Twitter last month that he had “funding secured” for a buyout of the electric-car company at $420 a share.
The deal with the S.E.C. will allow him to remain as chief executive, something he could have jeopardized if he had gone to battle with the agency.
It is not clear why Mr. Musk changed his mind so quickly.
The whipsaw events of the past few days followed a series of self-inflicted wounds by Mr. Musk.
His tweet about taking his company private, along with attacks on critics on social media, raised concerns with investors about whether Mr. Musk has become too focused on criticism from so-called short-sellers who had been making bets against him and Tesla. The company has recently been struggling to meet audacious production goals for its Model 3 sedan.
Mr. Musk is widely regarded by analysts and investors as the creative engine behind Tesla, and he has helped the company become one of the most valuable American carmakers. But Tesla has lurched from crisis to crisis over the past year, and has since scrambled to contain the fallout from Mr. Musk’s tweet.
The company, whose shares have been hit hard since the S.E.C. filed the lawsuit, did not immediately comment on the settlement. On Friday, its stock dropped almost 14 percent.
The terms of the settlement are slightly tougher than those that two people briefed on the talks said Mr. Musk had rejected on Thursday, which called for a two-year bar on serving as chairman and a $10 million fine.
Tesla, which is also settling with the S.E.C., will pay a $20 million penalty. The company was not charged with any fraud.
In addition, the company will add two independent directors and take steps to monitor Mr. Musk’s communications with investors. It will also create a permanent committee of independent directors to monitor disclosures and potential conflicts of interest.
Jay Clayton, the S.E.C. chairman, said the settlement with Mr. Musk and Tesla sent a message that “when companies and corporate insiders make statements, they must act responsibly, including endeavoring to ensure the statements are not false or misleading.”
In settling, Mr. Musk neither admitted nor denied misleading investors under the civil fraud charge, which means he cannot later say he did nothing wrong.
The settlement with the S.E.C. faulted Tesla for failing to make sure that information important to investors was disclosed in a proper and timely manner.
Mr. Musk had a good reason to reopen the settlement talks: The S.E.C., in suing him, had sought to bar him permanently from serving as a top executive or officer of Tesla or any other public company. Under the deal reached on Saturday, he will not only remain as chief executive, but will also stay on as a board member, just not as chairman.
“The total package of remedies and relief announced today are specifically designed to address the misconduct at issue by strengthening Tesla’s corporate governance and oversight in order to protect investors,” said Stephanie Avakian, co-director of the S.E.C.’s enforcement division.
Mr. Musk, according to people familiar with the negotiations, had been concerned about whether settling a civil fraud charge might affect the ability of Tesla and the other companies he runs, including SpaceX and the Boring Company, to raise money from investors in private placements and the debt markets.
But a Tesla spokesman said the S.E.C. had granted waivers to all of those companies so his settlement would not be held against them.
Waivers in such a situation are not uncommon, legal experts have said.
A Tesla spokesman said that Mr. Musk, a billionaire, would be buying $20 million in Tesla stock. The amount of stock being bought by Mr. Musk matches the penalty the company has to pay under the settlement, which was filed in federal court in Manhattan.
The S.E.C. reacted quickly after the Aug. 7 tweet, which caused an immediate surge in Tesla shares. Regulators served a subpoena on the company seeking information and moved to take testimony from Mr. Musk and others at the company, people familiar with the matter said.
Negotiations toward an initial settlement began about a week ago, after the S.E.C. said it was planning to send an official notice to Mr. Musk and Tesla that it was considering filing an enforcement action, those briefed on the talks said. By their account, all the parties thought a deal had been reached by Wednesday evening, and the plan was for a settlement with Mr. Musk and Tesla to be announced on Thursday.
Mr. Musk was said to have backed away from a settlement, in part, because he was concerned that he could not later tell investors that he had not done nothing wrong. But the settlement on Saturday requires him to do that.
In a so-called “admit nor deny” settlement, a settling party cannot later disavow the terms of the settlement.
After Mr. Musk was said to have rejected the deal on Thursday, his lawyers asked the S.E.C. to wait a couple of days so they could talk him into it, but the regulators said no, said another person familiar with the matter but not authorized to speak publicly.
Once the S.E.C. sued Mr. Musk, his lawyers continued to talk to him about moving forward with a settlement and eventually he agreed, this person said.
In the meantime, Mr. Musk had conversations with investors and friends like Mark Cuban, an entrepreneur who has had his own battles with the S.E.C., and they gave him a sense of how difficult it is to fight one of these suits, even if he eventually won, said people familiar with the negotiations.
The parties worked much of Friday and Saturday to get a deal done.
The settlement clears a big headache for Tesla, but other problems remain.
The S.E.C. is continuing to look into the company’s past claims about its production goals. And now with Mr. Musk agreeing to step down as chairman, Tesla’s board must decide who should replace him.