"The plaintiff is entitled to rescission," the Delaware judge said in her ruling.
The court's opinion directed the Tesla shareholder who challenged the $US56 billion ($NZ91 billion) pay plan to work with Musk's legal team on an order implementing the judge's decision.
Musk's lawyer did not immediately reply to an email seeking comment.
"Good day for the good guys," said an email from Greg Varallo, an attorney for the Tesla shareholder Richard Tornetta who brought the lawsuit.
The ruling can be appealed to the Delaware Supreme Court.
The judge, Kathaleen McCormick of Delaware's Court of Chancery, said the pay package did not meet the standard of a fair price.
"The incredible size of the biggest compensation plan ever - an unfathomable sum - seems to have been calibrated to help Musk achieve what he believed would make 'a good future for humanity'," wrote McCormick in her 201-page opinion.
Tesla's agreement with billionaire Musk is by far the largest compensation deal ever for an executive and it contributes a significant part of his fortune, which is one of the world's largest.
Tesla directors argued during a week-long trial that the company was paying to ensure one of the world's most dynamic entrepreneurs continued to dedicate his attention to the electric-vehicle maker.
Antonio Gracias, a Tesla director from 2007 to 2021, called the package "a great deal for shareholders" because he said it led to the company's extraordinary success.
Tornetta's lawyers argued the Tesla board never told shareholders that the goals were easier to achieve than the company was acknowledging and that internal projections showed Musk was quickly going to qualify for large portions of the pay package.
The plaintiff's legal team also argued the board had a duty to offer a smaller pay package or look for another CEO and that they should have required Musk to work full-time at Tesla instead of allowing him to focus on other projects.
Musk in 2022 bought social media company Twitter, which he renamed X, and he has founded several startups, including brain implant company Neuralink, tunneling venture the Boring Co and SpaceX, a rocket venture.
He testified during the compensation trial in November 2022 that the money would be used to finance interplanetary travel.
"It's a way to get humanity to Mars," he testified. "So Tesla can assist in potentially achieving that."
The package grants stock option awards allowing Musk to buy Tesla stock at heavily discounted prices as escalating financial and operational goals are met. He must hold the acquired stock for five years.
Musk qualified for all 12 tranches or performance targets in the plan. He was not guaranteed any salary.
The ruling will put the spotlight on Tesla's next round of compensation negotiations with the CEO. Musk said in a post on X in January that he was uncomfortable leading Tesla unless he had 25% of the voting control. The billionaire owned around 13% of the company at the time.
Tesla's value ballooned to briefly top $US1 trillion in 2021 from $US50 billion when the package was negotiated.
Amit Batish at Equilar, an executive pay research firm, estimated in 2022 that Musk's package was around six times larger than the combined pay of the 200 highest-paid executives in 2021.
In July, Tesla's directors agreed to return $US735 million to the company to settle shareholder allegations brought in a separate lawsuit filed in 2020 that they overpaid themselves.
The lawsuit challenged options that were granted to directors starting in June 2017.