Mr. Unsworth, who said in court documents that he had been exploring that cave system for six years, quickly became involved in the rescue effort. Soon after, Mr. Musk sent a team of engineers from the companies he leads — including Tesla, SpaceX and the Boring Company — to help as well.

At the time, Mr. Musk suggested the use of a small submarine, which Mr. Unsworth brushed off in a CNN interview, saying Mr. Musk could “stick his submarine where it hurts.”

Mr. Musk fired back in a series of angry tweets, referring to Mr. Unsworth as “pedo guy.” He later deleted the tweets, explaining that they were issued “in anger after Mr. Unsworth said several untruths & suggested I engage in a sexual act with the mini-sub.”

Mr. Musk passionately engages with fans and critics alike on Twitter, where he has 29.8 million followers. But his tweets have backfired on Mr. Musk in the past. Last fall, for example, he was replaced as chairman of the Tesla board as part of a settlement with the Securities and Exchange Commission over a tweet in which he said the company had the funding to go private.

And despite deleting the offending tweets about Mr. Unsworth, Mr. Musk continued to attack him using information from a private investigator who had reached out to Mr. Musk to suggest that the explorer had “skeletons in his cupboard,” the billionaire’s lawyers said in a September court filing.

According to that document, Mr. Musk paid the investigator $50,000 to look into Mr. Unsworth. Mr. Musk then relayed some of what the investigator had told him to a BuzzFeed News reporter, accusing Mr. Unsworth of having a 12-year-old bride, a claim that Mr. Unsworth has denied. BuzzFeed later reported that the investigator had been convicted of fraud and spent 18 months in a British prison for stealing hundreds of thousands of dollars from a business he co-founded.

In a court filing on Monday, Mr. Musk’s lawyers appeared to lay the groundwork for a First Amendment defense, arguing that the jury should be instructed to determine whether Mr. Musk’s words qualified as statements of fact or merely opinion. The lawyers also argued that Mr. Unsworth is a public figure rather than a private one, a distinction that would make it more difficult to prove defamation. The judge had already said last month that Mr. Unsworth is a private figure.