correction

An earlier version of this story incorrectly said Tesla's energy generation revenue fell in the first quarter of 2021. This version has been corrected.

WILMINGTON, Del. — Tesla chief executive Elon Musk took the stand in a Delaware court Monday to defend his company’s decision to buy solar-panel company SolarCity, arguing it was necessary not only for both companies but also for the future of the world’s climate.

He aggressively pushed back against questions from a lawyer representing a group of shareholders who allege Musk was acting in his own interest, not those of Tesla investors, when he led Tesla to acquire SolarCity for $2.6 billion in 2016. At the time, he owned a large portion of SolarCity, and it was run by two of his cousins.

“I think you are a bad human being,” Musk told the plaintiffs’ attorney, Randall Baron.

Musk insisted that the controversial deal will eventually pay off for shareholders and the global environment as Tesla refocuses on its solar-energy business in the quarters to come.

The testimony, which started Monday morning and continued through the day, was a contentious start to a trial expected to last two weeks after being delayed for more than a year because of the pandemic.

If the judge decides Musk used his influence at Tesla to push through the deal in opposition to shareholder interests, he may have to pay as much as $2 billion of his own money back to Tesla. That might not make a big financial difference to the billionaire, whose wealth is almost entirely tied up in Tesla stock anyway. But losing the trial would be a high-profile chastisement of the CEO’s brash leadership style.

Musk has long maintained that Tesla is building a top-to-bottom clean-energy company, and that buying SolarCity, which installs solar panels on residential rooftops, would eventually make business sense, even though SolarCity was struggling financially when Tesla acquired it.

Baron tried to show Musk hadn’t followed through on those commitments. Revenue at Tesla’s energy generation and storage division fell from 2018 to 2019, but has rebounded over 2020, according to the company’s financial filings.

Musk blamed Tesla’s failure to capitalize on the SolarCity acquisition on its need to refocus almost all of the company’s resources on getting its Model 3 car to market. After that, the pandemic got in the way, he said. He said he foresees Tesla Energy — the rebranded form of SolarCity — finally taking off in the quarters to come, fulfilling his vision of consumers buying panels to charge Tesla batteries that can power their homes and Tesla cars.

Baron played clips of Musk making similar projections at a 2019 deposition for the same trial and criticizing the plaintiffs for “wasting everyone’s time” with claims that would soon be proven wrong.

Baron’s questioning of Musk on Monday often led to testy exchanges between the two.

Early on, Baron sought to establish that Musk ran Tesla with a free hand in practice, despite being a minority shareholder and subject to oversight by the company’s board. He cited Musk’s 2021 move to change his official title at the company from CEO to “Technoking.”

“Well, I do have a sense of humor,” Musk replied. Then he added, smiling, “Well, I mean, I think I’m funny.”

Baron did not agree. “You didn’t just do it as a joke in a tweet,” he said. “You actually got lawyers involved in order to craft an SEC filing.” He went on, “You did that unilaterally. There was no board or committee meeting that said, ‘Hey, this would be really good for Tesla to change your name to Technoking.’ ”

Musk defended the move, saying it was in keeping with a strategy to generate free publicity for Tesla through humorous antics and that the board understood as much. “If we are entertaining, then people will write stories about us, and then we don’t have to spend money on advertising that would increase the price of our products,” he said.

At another point, Baron pressed Musk to acknowledge that he brooks no criticism at Tesla, responding to those who cross him with derision and even “rage-firings,” which Musk denied. Baron then played video clips from previous depositions in which Musk belittled and insulted Baron himself, as an example of how Musk acts according to his own personal whims rather than his firm’s best interest.

Musk took the opportunity to reiterate his claim that Baron deserves only contempt. With the judge’s permission, Musk went on to sketch a sordid history of Baron’s law firm, Robbins Geller Rudman & Dowd LLP, and his previous law firm, citing examples of criminal wrongdoing by a former partner at those firms’ predecessors. “You were mentored by criminals, then continued to be mentored by criminals,” Musk concluded.

“So you were derisive just because you didn’t like my résumé,” Baron said when Musk had finished.

That’s when Musk shot back, “I think you are a bad human being.”

The trial is taking place in Delaware chancery court, a staid environment that doesn’t allow live-streaming or tweeting from the courtroom. There is no jury, and the presiding judge is a longtime corporate law expert.

“This isn’t TV, this is before a corporate law judge whose life has been spent evaluating corporate conduct in a very clinical legal environment. You’re not playing to a jury,” said Charles Elson, a corporate governance expert and professor at the University of Delaware. Theatrics won’t work with the judge, Elson said.

“Does that kind of personality play well in a Delaware courtroom?” he said. “I don’t think it does.”

The testimony shifted focus Monday afternoon to the state of SolarCity’s finances, as Baron sought to show that Musk had hidden its poor outlook to push through an acquisition that wasn’t in Tesla’s best interest. “The reason Tesla sought to buy SolarCity at the time it did was because of SolarCity’s needs, not Tesla’s,” Baron charged.

Musk consistently denied that characterization, saying that integrating solar energy generation and battery storage was always crucial to Tesla’s plan to build for the world a more sustainable future. Even when it was in financial straits, Musk said, “I had faith in SolarCity’s future.”

Baron concluded Monday’s questioning by contesting Musk’s previous claim that he was “fully recused” from Tesla’s negotiations to acquire SolarCity. He intends to show that Musk was not only the driving force behind the deal, but pushed for a higher price tag. Musk’s testimony is expected to wrap up sometime Tuesday.