Mega-billionaire Elon Musk sold share of Tesla worth about $6.9 billion in the past several days, according to regulatory filings. The tech mogul later tweeted that he raised the money in case Twitter wins its battle to force Musk to buy the social network for $44 billion.

“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 tweeted about the stock sale on Tuesday night.

In April, Musk had sold about $8.4 billion in Tesla holdings to fund the Twitter buyout. At the time, he wrote that he had no more Tesla stock sales planned. On Tuesday, Musk affirmed that he would reacquire shares in Tesla if the Twitter deal doesn’t close. He now owns about 15% of the shares in Tesla.

After he clinched the $44 billion deal to buy Twitter on April 25, Musk began questioning Twitter’s longstanding claim that spam and fake accounts are less than 5% of total active users. On July 8, his lawyers informed the company Musk wanted to nix the deal over Twitter’s alleged inability to prove the metric.

Twitter turned around and sued Musk on July 12, seeking to force the world’s richest individual to consummate his binding pact to acquire the company. Lawyers for Twitter argue that Musk is looking for an excuse to bow out of the agree-upon terms after his personal net worth fell with the drop-off in Tesla’s stock price. The Delaware Court of Chancery has set Oct. 17 for the start of a five-day trial.

Analysts say Twitter has the upper legal hand in the case.

“In late April Musk said no further TSLA sales planned, however the situation has dramatically changed in our opinion heading into Delaware Court this October with the odds stacked against Musk winning in the eyes of the Street and his back against the wall,” Wedbush Securities analyst Dan Ives wrote. He raised the price target on Twitter from $30 to $50/share “reflecting the higher chances the deal now ultimately closes.”

Musk may also try to settle the case before it officially heads to court in October. At a minimum, Twitter stands to get $5 billion-$10 billion from Musk, according to Ives’ estimates. Musk may agree to pay upwards of $10 billion to walk away from the Twitter deal, legal experts have said.

In addition to the $15 billion-plus in cash from the sale of Tesla stock, Musk said he had lined up $7.1 billion financing commitments for the Twitter buyout from partners including Oracle’s Larry Ellison, Prince al-Waleed bin Talal of Saudi Arabia, Qatar’s sovereign wealth fund, Sequoia Capital, cryptocurrency exchange Binance.com, and a16z, the venture-capital firm founded by Marc Andreessen and Ben Horowitz.