Elon Musk threatened to cancel his agreement to purchase Twitter Inc. in a letter accusing the company of failing to comply with his request for data on the number of spam and fake accounts on the social-media platform.

Mr. Musk claims Twitter has refused to provide him with the information he needs to assess the number of spam and fake accounts. Twitter accepted Mr. Musk’s $44 billion bid to take the company private in April. Mr. Musk waived the detailed due diligence that buyers typically perform on targets as part of the deal.

Mr. Musk’s lawyer Mike Ringler stated in a letter to Twitter Chief Legal Officer Vijaya Gadde that Mr. Musk is entitled to the requested data, in part to facilitate the financing of the deal.

Mr. Musk has a group of 19 investors backing his deal. In filings, he also stated that he is in talks with other current Twitter shareholders, including co-founder Jack Dorsey, to transfer their shares to the private company.

According to a Twitter spokesman, the company “will continue to share information with Mr. Musk in order to complete the transaction in accordance with the terms of the merger agreement.” “We intend to close the transaction and enforce the merger agreement at the agreed-upon price,” he added.

In midday trading, Twitter shares fell nearly 2% to around $39; the all-cash deal is valued at $54.20 per share.

Mr. Musk’s latest letter is his most direct statement that he may abandon the deal, potentially igniting a lengthy legal battle between the two parties. As part of the agreement, both parties agreed to pay each other a $1 billion breakup fee if the deal fails for certain reasons, but specific scenarios must occur for those to become relevant. Twitter could also sue to compel Mr. Musk to complete the transaction.

Only in certain circumstances, such as if regulators try to block the deal or the debt financing falls through, would Mr. Musk be able to simply pay the termination fee and walk away from the transaction. Last week, Twitter announced that the window for federal antitrust regulators to block the deal had closed. Mr. Musk has also stated that he has secured funding.

For years, Twitter has publicly disclosed its own estimate of how many of its daily active users are false or spam accounts, putting the figure at less than 5% of all users. Mr. Musk has estimated that the figure is at least four times as high, at 20% of Twitter accounts.

On May 16, Twitter CEO Parag Agrawal tweeted that the company had shared information about how it estimates spam figures with Mr. Musk. Musk replied with a poop emoji.

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

Mr. Musk made an offer to buy Twitter for $44 billion in April, and the company accepted the offer the following month. Tesla Inc. CEO Elon Musk said in May that the deal was “temporarily on hold” due to his concerns about 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 or exit the takeover deal amid a swooning market. Under the terms of the agreement, Mr. Musk agreed not to disparage the company or its employees, but he has since attacked both.

Spam and fake accounts are an industry-wide issue that can cause problems for advertisers and poor user experiences. Bots, which are computer programs that can automate posts and replies, are commonly used to manage the accounts, which can be difficult to detect. Many bots are programmed to achieve illicit goals, such as spreading false information and duping people into spending money, according to tech and social-media analysts, but others serve more benign functions, such as sharing news and weather alerts.