SAN FRANCISCO — Twitter is still turning a profit — but it is continuing to have trouble holding on to its users.

On Thursday, the social networking service said it had 326 million monthly active users, down 9 million over the last three months and 4 million from a year ago. It was the second consecutive quarterly user decline for the company, even as President Donald Trump and other public figures regularly take to Twitter to express their views and engage their followers.

Despite the fall in users, Twitter said its third-quarter revenue rose 29 percent from a year ago, to $758 million. Net income totaled $789 million, compared with a loss a year earlier, in what was the fourth straight quarter of profits for the company. (Excluding a tax-related accounting gain, the quarter’s profit amounted to $106 million.)

Investors did not seem to mind the drop in monthly users. In premarket trading on Thursday, Twitter’s stock rose 14 percent.

The earnings report is a mixed bag for Jack Dorsey, Twitter’s chief executive. Dorsey, a Twitter co-founder who returned as chief executive in 2015, has been grappling with how to attract more users, as well as keep up its advertising business. In addition, Twitter has had to deal with disinformation, foreign interference and accusations of political bias.

Dorsey testified in Congress last month about foreign meddling and denied that Twitter was biased against conservatives. That same week, Twitter barred Alex Jones, the right-wing provocateur and creator of the conspiracy theorist website Infowars, for violating its abusive behavior policy.

Twitter has cracked down on fake and misleading accounts this year, which the social media company said on Thursday was partially responsible for its decline in users. The company also blamed a technical glitch that temporarily reduced the number of notifications sent to users this quarter and a product change that reduced automated activity.

In a statement, Dorsey said the company was “achieving meaningful progress in our efforts to make Twitter a healthier and valuable everyday service.” He said he and the company were prioritizing “the long-term health of Twitter while growing the number of people who participate in public conversation.”

Brian Wieser, a senior analyst with Pivotal Research, said Twitter was in a tough position because its efforts to improve the health of the platform might drive away some investors and users in the short run, even though it would be better for the service down the road. He called the situation a “paradox” for the company.

Twitter faces another test soon: the Nov. 6 midterm elections. This month, Twitter updated its rules to ban the dissemination of certain hacked materials and expanded its efforts to take down dormant fake accounts. The company has also worked to secure the accounts of elected officials and candidates by giving them special labels on their Twitter profiles and prompting candidates to enable extra security features on their accounts.