Elon Musk agreed Saturday to step down as chairman of Tesla and pay a $20 million fine in a deal to settle charges brought this week by the Securities and Exchange Commission.

Under the settlement, which requires court approval, Musk will be allowed to stay as CEO but must leave his role as chairman of the board within 45 days. He cannot seek reelection for three years, according to court filings.

He accepted the deal with the SEC "without admitting or denying the allegations of the complaint," according to a court document.

Separately, Tesla agreed Saturday to pay $20 million to settle claims it failed to adequately police Musk's tweet.

"The $40 million in penalties will be distributed to harmed investors under a court-approved process," the SEC said in a press release.

The company also agreed to appoint two new independent directors to its board and establish a board committee to oversee Musk's communications.

Tesla declined to comment. A spokesperson confirmed Musk will be permitted to remain a member of the board.

The announcement from the SEC comes two days after the agency filed a lawsuit against Musk, claiming he misled investors. The suit centers on tweets Musk sent on August 7 in which he said he had secured funding to take Tesla private at $420 a share, causing the company's stock to soar. He had not secured the funding, the SEC said.

The lawsuit sought to ban Musk from serving as an officer or director of any publicly traded company.

Musk called the SEC's suit "unjustified."

"I have always taken action in the best interests of truth, transparency and investors," he said. "Integrity is the most important value in my life and the facts will show I never compromised this in any way."

CNBC, citing unnamed sources, reported that the agency filed the suit on Thursday after Musk refused an earlier settlement offer. Under that deal, Musk would have had to pay a "nominal fine" and leave his role as chairman for two years. He chose not to accept the terms because "because he felt that by settling he would not be truthful to himself," according to the outlet.

A representative for Musk did not immediately reply to CNN's request for comment Saturday.

Jay Dubow, a partner at Pepper Hamilton and a veteran of the SEC's enforcement division, said it was "unusual" that the SEC agreed to let Musk stay on as chief executive but exit the chairman role.

It's surprising considering "the conduct at issue, if [the SEC] really thought it was egregious," Dubow said. "The CEO is certainly more involved than the chairman in day-to-day operations."

He suggested the SEC may have determined that removing Musk as CEO would cause more harm to Tesla's share price, and thus harm investors.

Barclays analyst Brian Johnson estimated in a recent note that Tesla's stock has a $130 "Musk premium," which could disappear if he leaves.

Still unclear is whether or not the Department of Justice will file criminal charges against Musk.

Tesla confirmed earlier this month that the DOJ was investigating whether Musk's comments about taking his company private constituted criminal activity.

Dubow, the former SEC official, said he suspects nothing will come of it.

"My guess is that it's still possible the DOJ will pursue something, but...it's more likely than not that the DOJ chooses not to pursue this," he said.

The settlement has likely assuaged the SEC, mitigating the DOJ's incentive to act.