Entrepreneur Elon Musk says his tech companies Tesla and SpaceX survived "by the skin of their teeth" and that he wouldn’t let his friends invest as he didn’t want to lose their money.

Speaking in a Q&A session at the South by South West (SXSW) conference in Austin, Texas, Musk revealed that both the electric car company and his space travel firm almost went bankrupt in 2008.

"I gave both SpaceX and Tesla a probability of less than 10% likely to succeed," he said. "At the beginning in 2002, I wouldn't even let my own friends invest as I didn't want to lose their money.

"SpaceX is alive by the skin of its teeth, and so is Tesla - if things had just gone a little differently, both companies would be dead.”

PayPal co-founder Musk made $180 million (£130m) when the online payments system was bought by eBay in 2002 and said he put $90m into SpaceX and Tesla, but costs spiralled out of control.

"I could put it all into one company, and the other company would definitely die, or if I split it into both SpaceX and Tesla then they both might die," he said.

“When you put your energy into building something, it's your baby, so I couldn't choose. I put the money into both, and thank goodness they both came through."

He said he formed SpaceX because he didn’t feel that mankind had done enough to explore space. The 50th anniversary of the Apollo 11 moon landing is next year.

"I wondered why we weren't making progress with getting people on the moon, and where are all the space hotels we were promised in 2001: A Space Odyssey?" he said.

"The genesis of SpaceX was not to create a company, but how do we get NASA's budget to be bigger?"

SpaceX is working on a 100-metre ship codenamed the BFR – Big F****** Rocket – which Musk said will fly for the first time next year and which will eventually be sent to Mars.

The most powerful rocket system yet built by the company, it is intended to be reusable and allow for interplanetary travel.

Musk said it will be crucial to build bases on Mars so humankind can survive a Third World War.

“We are building, the first Mars interplanetary ship right now,” he said.

“I think we'll be able to do short flights, sort of up-and-down flights, probably sometime in the first half of next year.

“It’s important to get a self-sustaining base on Mars because it’s far enough away from Earth that it’s more likely to survive than a moon base.

“If there’s a Third World War we want to make sure there’s enough of a seed of human civilisation somewhere else to bring it back and shorten the length of the dark ages.”

On artificial intelligence, he added: “Mark my words, AI is much more dangerous than nukes. So why do we have no regulatory oversight?”