Washington: Elon Musk has sold nearly $7 billion worth of Tesla shares, according to legal filings, amid a high-stakes legal battle with Twitter over a $44 billion buyout deal.

The Tesla boss sold some 7.9 million shares between August 5 and 9, according to filings published on the Securities and Exchange Commission's website on Tuesday.

"In the (hopefully unlikely) event that Twitter forces this deal to close and some equity partners don't come through, it is important to avoid an emergency sale of Tesla stock," Musk, the world's richest man, wrote on Twitter late Tuesday.

Twitter is locked in a legal battle with the mercurial Tesla boss over his effort to walk away from the April agreement to buy the company, and a judge has ordered that a trial will begin in October.

Musk has filed a countersuit, accusing Twitter of fraud and alleging the social media platform misled him about key aspects of its business before he agreed to a $44 billion buyout.

The move comes after Musk sold around $8.5 billion worth of shares in the electric carmaker in April as he was preparing to finance the Twitter deal. He tweeted at the time: "No further TSLA sales planned after today."

Tesla rose 3.4 percent to $879 before the start of regular trading Wednesday, while Twitter jumped 4.3 percent to $44.69, Bloomberg reported.

Musk has now sold about $32 billion worth of Tesla shares since November.

"He is cashing up for Twitter," Charu Chanana, a strategist at Saxo Capital Markets told Bloomberg News.

Chanana said she believed Musk may be attempting to take advantage of a Tesla share price rebound of about 35 percent since late May.

"The bear market rally has started to falter, and further repricing of Fed expectations could mean more pain for equities ahead, especially in tech."

Analysts say Musk may continue selling Tesla stock.

"Musk said at the Tesla shareholder meeting that any weakness in the share price was a buying opportunity, and then 24 hours later started selling stock himself," Jim Dixon, a senior equity sales trader at Mirabaud Securities, told Bloomberg News.

Dixon added that it was "very unlikely" that Musk was finished selling Tesla stock.

Tesla share prices have been tied to the fate of Musk's Twitter deal in recent weeks, first slumping over concerns that pursuing the deal could distract him and lead to unnecessary financial risk, and then rebounding when he said he wanted to abandon the takeover.

Musk's deal to buy Twitter included a provision that if it fell apart, the party breaking the agreement would pay a termination fee of $1 billion under certain circumstances.

At a net worth of $250 billion, Musk tops the Bloomberg Billionaires Index, although he has lost $20.1 billion since the start of the year, mainly due to the decline in Tesla's stock price.