LOS ANGELES — Tesla CEO Elon Musk will have to go to trial to defend himself for mocking a British diver as a pedophile in a verbal sparring match that unfolded last summer after the underwater rescue of youth soccer players trapped in a Thailand cave.

A federal court judge in Los Angeles set an Oct. 22 trial date in a Friday court filing that rejected Musk’s attempt to dismiss a defamation lawsuit filed by British diver Vernon Unsworth.

Musk called Unsworth a “pedo” in a July 15 post on this Twitter account after Unsworth, in an interview with CNN, dismissed Musk’s attempts to help rescue the soccer players as a “PR stunt.” Unsworth also derided the submarine that Musk had built for a rescue mission, prompting Musk to lash back on this Twitter account, which had 22.5 million followers at the time

Musk contended his insult was protected from legal action, but the judge overseeing the case disagreed.

Unsworth is seeking more than $75,000 in damages from Musk, a multibillionaire. The suit also seeks a court order prohibiting Musk from making any further disparaging comments.

This is the second time in less than a year that Musk’s free-wheeling comments on Twitter have saddled him with legal headaches.

Last year, Musk and Tesla reached a $40 million settlement of allegations that he misled investors with a tweet declaring he had secured financing for a buyout of the electric car maker. He then had to go to court earlier this year to defend himself against assertions that he had violated an agreement with the Securities and Exchange Commission about his tweeting.