The celebrity chief executive completed about eight hours of testimony over two days to defend himself against a lawsuit brought by union pension funds and asset managers who allege he strong-armed Tesla directors into buying the cash-strapped SolarCity for $2.6 billion.

Musk at the time owned a 22% stake in both Tesla and SolarCity, which was founded by his cousins. The Tesla shareholders want Musk to be ordered to return the value of the deal to Tesla.

Musk completed his testimony by fielding several questions about the timing and necessity of the deal from Vice Chancellor Joseph Slights, the judge who will decide if Musk is liable.

Musk said Tesla was struggling in 2016 to develop its Powerwall battery system because it was difficult to integrate with other solar power systems.

"If we have a whole bunch of third-party solar systems, it's a messy situation. We needed solar within Tesla," he told the judge.

Shareholders have questioned the need to buy SolarCity and asked Musk if other solar companies were considered as acquisition targets.

Central to the case are claims that despite owning only 22% of Tesla, Musk was a controlling shareholder due to his ties to board members and domineering style. If plaintiffs can prove this, it increases the likelihood that the court will conclude the deal was unfair to shareholders.

Musk has consistently told the court that the Tesla board primarily handled the SolarCity deal and that he recused himself from price negotiations.

Shareholder attorney Randall Baron on Tuesday pressed Musk to explain meeting notes taken by a financial advisor showing Musk suggested the board offer a $28.50 share price for SolarCity.

"I was making the obvious point that any offer, if not publicly defensible, will be rejected by SolarCity shareholders," Musk said.

In response to questions from his own lawyer Evan Chesler, who was trying to show Musk did not dominate board discussions, Musk noted his suggestion was overruled at that meeting.

Baron asked Musk to explain why he reviewed deal packets for the Tesla board before they were sent to directors, suggesting the CEO was controlling the flow of information.

"It's part of the board process to make sure they have full and accurate information," Musk testified.

Musk repeatedly defended the SolarCity deal by saying the company had to be quickly acquired or find financing to solve its dangerous cash shortage.

Legal experts said the judge will be looking for evidence that Musk threatened board members or that directors felt they could not stand up to him.

Elon Musk's brother Kimbal, a Tesla director who is listed in court documents as a witness for both sides, was asked by the plaintiffs' lawyers if he thought his brother's actions in regard to the SolarCity deal were appropriate considering he said he recused himself.

Kimbal Musk responded that he did not understand how a CEO could be recused from deal negotiations.

"How could the CEO not be involved in some form," he said. "That sounds not possible."

Kimbal Musk, other board members and others involved in the 2016 deal will testify for the duration of the trial, which started on Monday and is expected to last two weeks.

The company's directors settled allegations from the same lawsuit last year for $60 million, paid by insurance, without admitting fault.

(Reporting by Tom Hals in Wilmington, Delaware; Editing by Noeleen Walder, Andrea Ricci and Sonya Hepinstall)

By Tom Hals and Sierra Jackson