That’s a high price to pay for a stupid pot joke.

Elon Musk must step down as chairman of the board of Tesla for three years — and he and the car company will each forfeit $20 million — under a punishing settlement forced by the Securities and Exchange Commission.

The settlement is Musk’s penalty for a market-scrambling joke tweet the billionaire entrepreneur and rocket scientist sent out two months ago “announcing” a $420-a-share takeover price for the company.

The number “420” is slang for marijuana use.

When first questioned by the SEC, Musk confessed that he had settled on the $420 figure to make a dumb pot joke to impress his girlfriend. At the time, Musk was dating the pop singer Grimes.

Musk will remain chief executive of Tesla, the SEC said in announcing the settlement Saturday.

But he must add two independent directors and submit to the company monitoring his communications with investors.

In accepting the settlement terms, Musk has neither admitted nor denied the SEC’s civil allegations that he committed fraud by misleading his investors.

The settlement terms are slightly tougher than those Musk had rejected during negotiations Thursday, The New York Times reported, citing two people briefed on the talks.

Those earlier terms would have barred him from serving as chairman for two years instead of three and would have cost him a $10 million fine instead of $20 million.

But it could have been worse.

The SEC made an initial hardball offer before filing Thursday’s lawsuit, under which Musk would have stepped down for two years as both chair and CEO, effectively severing all ties to Tesla.

The SEC slap comes two months after Musk earned the feds’ ire with a Wall Street-blindsiding Aug. 7 tweet teasing that he planned to take the company private.

“Am considering taking Tesla private at $420. Funding secured,” read the tweet.

Market chaos ensued. Shares skyrocketed $16 in five minutes, to $371.07.

But Tesla’s own executives had been caught unawares.

The company’s head of investor relations immediately sent a text to Musk’s chief of staff asking, “Was this legit?” the SEC later revealed in suing Tesla and Musk on Thursday.

It turned out that Musk was being less than legit. He had calculated a potential share price of $419 by taking that day’s closing share price and tacking on a 20 percent premium, the feds alleged in the lawsuit.

But there was in fact zero financing secured.

“Musk stated that he rounded the price up to $420 because he had recently learned about the number’s significance in marijuana culture,” the SEC suit reads. The suit adds that Musk “thought his girlfriend ‘would find it funny.’ ”

“In truth and in fact,” the SEC suit continues, “Musk had not even discussed, much less confirmed, key deal terms, including price, with any potential funding source.”

The SEC claimed in its suit that “Musk’s false and misleading public statements and omissions caused significant confusion and disruption in the market for Tesla’s stock and resulting harm to investors.”

The SEC’s lawsuit caused only more tumult. Tesla stocks took a more-than-13 percent tumble.

The South African native and wunderkind — who was 12 when he sold his first computer code, for a video game called “Blastar,” to a computer magazine for $500 — has kept his stock volatile and his investors on their toes with his recent antics.

Earlier this month, Tesla fell to its lowest point in five months ­after he smoked marijuana on a Joe Rogan podcast.

Recreational smoking is legal in California, but Musk raised eyebrows with his rambling remarks, including his assertion, “I’m not a business magnate. I’m a business magnet.”

Musk has also taken deserved hits for making unsubstantiated claims on Twitter that Vernon ­Unsworth, a caver who helped rescue 12 boys and their soccer coach from a flooded cave in Thailand in July, is a “pedo,” or pedophile.

“He owns enough stock that he is dar from voiceless,” said Columbia law professor John Coffee.

“But maybe now Tesla will act with more rationality and maturity.”