A judge approved a $40 million settlement by Tesla and Chief Executive Elon Musk with the U.S. Securities and Exchange Commission, resolving government claims that Musk misled the public with a flurry of tweets about a plan to take the company private.

U.S. District Judge Alison Nathan in Manhattan signed off on the accord Tuesday after the electric-car maker, Musk and the regulatory agency said in a detailed joint filing that the deal was in the best interest of investors. The company will pay $20 million and Musk will also pay $20 million.

The judge’s decision was largely expected, even after Musk muddled the process by insulting the SEC in a series of tweets just a few days after reaching the settlement deal.

Resolution of the case should allow Palo Alto-based Tesla to move on from the latest distraction to its core business of pumping out electric vehicles at a sufficient clip to please investors, some of whom have been rattled by Musk’s social-media behavior.

The dispute was triggered by Musk’s Aug. 7 tweet that he had “funding secured” to take Tesla private. The shares surged until trading was halted temporarily. Within hours, questions began to swirl around Musk’s claims, and the SEC quickly opened an investigation. The agency moved with unusual speed, questioning Musk, Tesla’s board and other executives.

Musk and Tesla agreed to resolve the allegations without admitting or denying wrongdoing. The plan called for their combined $40 million in penalties to be distributed to harmed shareholders through a court-approved process, the SEC has said.

Within days of the settlement, Musk shot off a tweet referring to the SEC as the “Shortseller Enrichment Commission” and sarcastically praising the regulator’s work. Experts said the tweet could be viewed, problematically, as a denial of wrongdoing by Musk, but they said it wasn’t likely to derail the deal.