Elon Musk was granted a $55.8 billion (£44 billion) compensation package by the electric vehicle manufacturer Tesla in 2018, but the agreement was revoked by a Delaware state judge.
A stockholder filed the complaint, claiming there had been an overcharge.
Judge Kathaleen McCormick ruled that the Tesla board’s approval of the pay package was “deeply flawed.”
In a post on X, which is owned by Mr Musk and formerly known as Twitter, he wrote: “Never incorporate your company in the state of Delaware”.
The pay deal was the biggest ever in corporate history, helping to make Mr Musk one the richest people in the world.
During the week-long trial, Tesla directors argued the deal was made to ensure that one of the world’s most dynamic entrepreneurs continued to dedicate his attention to the company.
But the judge ruled that Tesla and Mr Musk’s attorneys “were unable to prove that the stockholder vote was fully informed”, and that he had “extensive ties with the persons tasked with negotiating on Tesla’s behalf”.
“Given the judge found Mr Musk to be in control of the board, it’s hard to justify a transaction like this,” Brian Quinn, a professor at Boston College Law School, told the BBC.
In her 200-page ruling, Judge McCormick called the compensation “an unfathomable sum” that was not fair to shareholders.
The judge also said the compensation package had been negotiated by Tesla’s directors who had been “swept up by the rhetoric” surrounding Mr Musk’s “superstar appeal”.
Greg Varallo, an attorney for the Tesla shareholder Richard Tornetta who brought the lawsuit in 2018, said it was a “Good day for the good guys,” in an email reported by the Reuters news agency.
The ruling can be appealed to the Delaware Supreme Court.
The pay deal was the biggest ever in corporate history, helping to make Mr Musk one the richest people in the world.
Shares in Tesla were down by around 3% in extended New York trade. They have lost more than 20% of their value so far this year.
Mr Musk also posted on X: “I recommend incorporating in Nevada or Texas if you prefer shareholders to decide matters”. He then posted a poll asking his followers whether or not Tesla should “change its state of incorporation to Texas, home of its physical headquarters”.
“That is a question for Tesla shareholders, not his Twitter followers,” said Professor Quinn.
“He treats Tesla like his own but even if he calls himself the ‘Technoking of Tesla’, he is not the majority owner,” he added.
As well as being the chief executive and a major shareholder of Tesla, Mr Musk also owns several other companies including the social media platform X, the rocket company SpaceX, and the brain chip firm Neuralink.
After selling a large chunk of his stake in Tesla to buy X, Mr Musk currently owns about 13% of the social media platform but has recently said he wants a bigger stake in the electric car maker.
Mr Musk said he is concerned about Tesla’s investments in artificial intelligence (AI) technology.
“I am uncomfortable growing Tesla to be a leader in AI and robotics without having 25% voting control,” he said in a social media post.
He said the current shareholder structure makes Tesla vulnerable to a “takeover by dubious interests” and he wants more control over its direction.
“Unless that is the case, I would prefer to build products outside of Tesla,” Mr Musk added.