A U.S. judge on Tuesday approved the settlement between the Securities and Exchange Commission, Tesla and its CEO Elon Musk.

Musk agreed to pay a $20 million fine and step aside as Tesla's chairman for three years to settle charges that could have forced his exit from Tesla.

The company also accepted a $20 million fine, despite not being charged with fraud.

Tesla shares rose 4 percent to $269.81 in morning trading.

The company's shares had taken a hit last month after the U.S. securities regulator accused Musk, 47, of fraud over "false and misleading" tweets on Aug. 7 that promised to take the electric carmaker private and said funding had been secured.

As per the settlement announced on Sept. 29, Tesla must appoint an independent chairman, two independent directors and a board committee to set controls over Musk's communications.

On Oct. 4, just hours after the court ordered him and the SEC to explain why their settlement was fair and reasonable, Musk appeared to mock the SEC on Twitter.

"Just want to that the Shortseller Enrichment Commission is doing incredible work," Musk, a frequent critic of investors betting against the company, wrote. "And the name change is so on point!"