Elon Musk threatened to terminate his deal to buy Twitter Inc. in a letter accusing the company of not complying with his request for data on the number of spam and fake accounts on the social-media platform.

Mr. Musk said Twitter has refused to provide the data necessary for him to facilitate his own evaluation of the number of spam and fake accounts. In April, Twitter accepted Mr. Musk’s $44 billion bid to take over the company and go private.

In a letter to Twitter Chief Legal Officer Vijaya Gadde that was disclosed in a regulatory filing Monday, Mr. Musk’s lawyer Mike Ringler said Mr. Musk is entitled to the requested data, in part so that he can facilitate the financing of the deal.

Mr. Musk has lined up a group of 19 investors to back his deal. He has also said in filings that he is holding talks with other current Twitter shareholders, including co-founder Jack Dorsey, to roll their shares over into the private company.

“In any event, Mr. Musk is not required to explain his rationale for requesting the data, nor submit to the new conditions the company has attempted to impose on his contractual right to the requested data,” Mr. Ringler wrote. “At this point, Mr. Musk believes Twitter is transparently refusing to comply with its obligations under the merger agreement.”

“This is a clear material breach of Twitter’s obligations under the merger agreement and Mr. Musk reserves all rights resulting therefrom, including his right not to consummate the transaction and his right to terminate the merger agreement,” he said.

A Twitter spokesman said the company “will continue to cooperatively share information with Mr. Musk to consummate the transaction in accordance with the terms of the merger agreement.” He added: “We intend to close the transaction and enforce the merger agreement at the agreed price and terms.”

Shares of Twitter fell around 1.5% to $39.57 Monday; the all-cash deal is priced at $54.20 a share.

Also on Monday, Texas Attorney General Ken Paxton

launched an investigation into Twitter, saying the company may have falsely reported its fake bot accounts in violation of the Texas Deceptive Trade Practices Act. Mr. Paxton’s office ordered Twitter to produce documents on how it calculates and manages its user data and how that information relates to its advertising businesses. Mr. Paxton’s office said Twitter has until June 27 to respond to its demands.

“Texans rely on Twitter’s public statements that nearly all its users are real people,” said Mr. Paxton, a Republican. “It matters not only for regular Twitter users, but also Texas businesses and advertisers who use Twitter for their livelihoods.”

Mr. Musk last year moved the headquarters for his automotive company, Tesla Inc., to Texas from California. The rocket company he runs, Space Exploration Technologies Corp., has large operations in Texas as well.

Mr. Paxton and Twitter have clashed in the past. Last month a federal appeals court ruled that Texas for now can enforce a law prohibiting the internet’s biggest social-media platforms, including Twitter, from suppressing users’ content based on the viewpoint of their speech. Mr. Paxton responded to the ruling with a tweet saying he supported the law and that the Fifth Circuit “made the right call here.”

Mr. Musk’s latest letter is his clearest statement that he may try to abandon the deal, potentially spurring what could be a protracted legal battle between the two sides. As part of the deal, both sides agreed to pay each other a $1 billion breakup fee if they cause the deal not to happen for certain reasons. Twitter could also sue to force Mr. Musk to go through with the transaction.

There are only specific scenarios under which Mr. Musk would be able to simply pay the termination fee to walk away from the transaction, including if regulators try to block the deal or the debt financing falls through. Twitter said last week that the window has closed for federal antitrust regulators to block the deal. And Mr. Musk has said he has financing lined up.

For years, Twitter had publicly disclosed its own estimate of how many of its daily active users represent false or spam accounts, putting the percentage at fewer than 5% of its monetizable daily active users. Mr. Musk has pegged the figure at least four times as high at 20% of Twitter’s accounts.

Twitter CEO

Parag Agrawal on May 16 tweeted that the company had shared information with Mr. Musk about how it estimates spam figures. Mr. Musk responded with a poop emoji.

In his letter Monday, Mr. Ringler confirmed Mr. Musk received a response from Twitter on June 1, but said it didn’t satisfy Mr. Musk’s requests. “If Twitter is confident in its publicized spam estimates, Mr. Musk does not understand the company’s reluctance to allow Mr. Musk to independently evaluate those estimates,” the letter said.

As part of the deal, Mr. Musk had waived detailed due diligence that buyers typically perform on targets. In a response to a tweet Monday, Mr. Musk suggested him waiving due diligence didn’t apply to any potential misstatements by Twitter.

Legal experts offered different theories on what may be driving Mr. Musk and his legal team.

“This sounds like they’re trying to shoehorn a due diligence termination right into an agreement that does not have one,” said David Hoppe, a mergers and acquisitions, tech and media attorney with Gamma Law in San Francisco.

Mr. Musk would need to argue that something happened since the time he signed the deal that raised new doubts about the estimates that Twitter provided on the amount of spam and fake accounts on its platform, he said.

“I’m sure Musk’s legal team wishes there was some change of circumstance that would raise doubts about the legitimacy of those numbers, but nothing’s really changed,” Mr. Hoppe said. “There’s no bombshell.”

By linking the fake-account issue to Mr. Musk’s ability to secure financing for the deal, his legal team could be indicating the exit ramp they may try to pursue to extract their client from the transaction, said Ben Means, a professor at the University of South Carolina School of Law. “Financing obviously is necessary to close the transaction,” he said.

Eric Talley, a professor at Columbia Law School, said that while Mr. Musk has the right to request information, Twitter may be unable to share it if doing so would breach another person’s legal rights or undermine the company’s competitive position.

Mr. Musk offered to buy Twitter for $44 billion in April, and the company agreed to the deal the same month. In May, the Tesla chief executive said the deal was “temporarily on hold” because of his concerns over the company’s accounting of the number of fake accounts on its platform.

Mr. Musk’s escalation of the bot issue last month raised suspicions among observers that he is using it as a negotiating tactic to lower the price amid a swooning market, or to exit the takeover deal. Mr. Musk had agreed not to disparage the company or the people who work there under the deal, though has since taken aim at both.

Spam and fake accounts are an industrywide problem and can cause problems for advertisers and bad experiences for users. The accounts can be difficult to detect and are commonly managed by bots, which are computer programs that can automate posts and replies.

Mr. Musk has had unusually extensive interactions with bots. As a habitual tweeter with more than 95 million followers, the Tesla CEO likely has far greater exposure and experience with fake and spam accounts than most on the social-media platform, researchers say. Around 70% of Mr. Musk’s followers on Twitter are spam, fake or inactive, versus 41% for all other accounts with between 65 million and 120 million followers, according to an estimate last month from SparkToro LLC, a maker of audience-research software.

Write to Will Feuer at will.feuer@wsj.com and Sarah E. Needleman at sarah.needleman@wsj.com