Image copyright Reuters Image caption Elon Musk said he had "spoken in anger"

Tech entrepreneur Elon Musk has apologised to a British cave diver he called "pedo guy" in a row over the cave rescue in northern Thailand.

He said he had "spoken in anger" after Vern Unsworth ridiculed a mini-submarine he had commissioned for the rescue effort as a "PR stunt".

"His actions against me do not justify my actions against him, and for that I apologise," Mr Musk said.

Mr Unsworth has said he may sue for being called a "paedophile".

Twelve boys and their football coach were rescued from deep within a cave earlier this month after being trapped for more than two weeks.

Mr Unsworth's knowledge of the cave complex is said to have played a key role in the rescue effort.

He travelled into the caves in the first days after the boys went missing and helped bring in top international cave rescue experts for the mission.

Mr Musk, head of the SpaceX and Tesla companies, visited the command centre in Thailand during the rescue, announcing he had left the rescuers a mini-submarine.

What did Musk say?

In a reply to another user on Twitter on Wednesday, referring to an article about his involvement in the rescue mission, he wrote that he was apologising to both Mr Unsworth and the companies he led.

"The fault is mine and mine alone," he declared.

At the same time, he accused Mr Unsworth of telling "untruths" about his mini-submarine, which was not used in the rescue.

How did the row erupt?

Mr Unsworth had said the mini-sub would have had "absolutely no chance of working" - and suggested Mr Musk could "stick his submarine where it hurts".

The entrepreneur fired back with a tweet where, without using Mr Unsworth's name, he referred to a "British expat guy who lives in Thailand".

He said he would make a video showing the mini-sub making it deep inside the cave "no problemo", adding, "Sorry pedo guy, you really did ask for it."

The tweet, sent to his more than 22 million followers, was later deleted.

No charges or complaints had ever been filed against Mr Unsworth, Reuters news agency quoted an unnamed police officer in Thailand's Chiang Rai area as saying.

Separately, Mr Musk attacked the Thai official in charge of the command centre, Narongsak Osotthanakorn, for saying the mini-sub had been "not practical", though "technologically sophisticated".

Mr Musk said Mr Osotthanakorn had been "described inaccurately as 'rescue chief'" and was "not the subject matter expert".

How did the cave drama unfold?

The boys, aged 11 to 16, and their 25-year-old coach became trapped by floodwater while exploring the Tham Luang cave system on 23 June.

Media playback is unsupported on your device Media caption Thai cave rescue: Saying sorry to cave spirit Nang Norn

Cut off from the outside world, they were not found by divers until 2 July and a complex rescue operation ensued, during which one diver lost his life.

The 13 were finally extracted in groups over three days, the last emerging on 10 July.

Mr Musk visited the scene when it was still unclear whether divers on their own would be able to bring out the boys.

He tweeted an email from Richard Stanton - one of two British caving experts called in to front the rescue - who had urged the business leader to build the capsule as quickly as possible.

What other controversies have involved Musk?

Media playback is unsupported on your device Media caption Rockets, cars and flame throwers: Who is Elon Musk?

The entrepreneur has been likened in the past to a genius behaving like a playground bully.

He told financial analysts at a Tesla earnings call this year that their "boring bonehead questions" were "not cool".

A leaked work email shows he advised Tesla staff to keep big meetings "very short" and to walk out of a meeting or end a phone call if it was failing to serve a useful purpose.

More bizarrely, last month he scrapped on Twitter over rights to an image of a farting unicorn, before dismissing the row as "kinda lame".