SAN FRANCISCO — A British cave diver involved in the rescue of 12 Thai soccer players and their coach said he would consider taking legal action against Elon Musk after the Tesla Inc. and SpaceX chief executive suggested on Twitter that the diver was a pedophile.

On Monday, Vernon Unsworth told the Guardian that he was “astonished and very angry” after hearing of Musk’s tweets.

“I believe he’s called me a pedophile,” he said.

When asked by reporters at the cave site about whether he would consider taking legal action against Musk, Unsworth said, “Yes, it’s not finished.”

SpaceX and Tesla did not immediately respond to a request for comment.

The war of words comes after Unsworth told CNN this month that Musk’s plan to deploy a mini-submarine built by SpaceX engineers to save the children had “absolutely no chance of working.”

“He can stick his submarine where it hurts,” Unsworth said when asked about Musk’s plan.

Musk shot back Sunday, tweeting that he’ll send a sub through the cave to prove it could have worked, followed by an attack on Unsworth:

“We will make one of the mini-sub/pod going all the way to Cave 5 no problemo. Sorry pedo guy, you really did ask for it.” Musk tweeted.

Challenged on the social media site to provide evidence to support his accusation, Musk tweeted: “Bet ya a signed dollar it’s true.”

(Musk’s pedophile-related tweets were deleted Sunday afternoon).

The drama comes amid a crisis at Tesla, which has yet to prove that profitable, high-quality mass production of its Model 3 electric sedan is achievable.

The accusation and reaction took some attention away from a different social media flurry on Saturday, when Musk took to Twitter to explain why he donated money to the Republican Party — specifically, $38,900 to a Republican political action committee called Protect the House.

The donation, reported originally by ProPublica, brought a flood of Twitter announcements of Tesla vehicle cancellations from environmentally minded potential customers — although there’s no way for anyone outside of Tesla to determine how many of those people had actually had ordered a Tesla.

The volume of cancellation announcements on Twitter put Musk on defense, who issued a series of tweets.

“I do not actually see the checks (changed that policy today),” Musk said in one. “A nominal annual amount goes out automatically to both parties to maintain dialogue. I have given vastly more to humanitarian causes.”

Companies and their top executives do regularly give money to both Democrats and Republicans.

However, Tesla customers tend to be people with high levels of disposable income who are also concerned about climate change and pollution.

Tweeters asked how Musk could justify contributions to “protect” a House of Representatives and a political party filled with climate-change deniers.

Tesla, as well as General Motors Co., have been lobbying to extend a $7,500 tax credit for customers buying electric cars. Those credits are set to be reduced for Tesla by the end of this year, and for General Motors next year. Tesla said last week that it had sold more than 200,000 vehicles in the United States to date, the point at which a company’s tax credits begin to decline.

Makers of all-electric cars and their buyers qualify for the $7,500 subsidy until the company sells a cumulative 200,000 vehicles in the United States. At that point, the full credit continues for a calendar quarter. For six months after that, the subsidy is reduced to $3,750. The next six months, $1,875. Then it disappears.

Wall Street Journal columnist Charley Grant tweeted that Republicans in Congress could vote to extend Tesla’s full credits. “Don’t be so sure those tax credits are going away just yet,” he said, noting a report of Musk’s political contributions.