SAN FRANCISCO — Twitter often feels like the digital equivalent of a swamp.

The Russians used the platform to disrupt the 2016 election. Famous people buy fake followers to make themselves seem more famous. Prominent members of the chattering class have been signing off for good. Sometimes it seems as if no one loves the service except for the president of the United States.

As a business, however, Twitter might finally be starting to work.

On Thursday, it reported a profit in the fourth quarter, the first black ink since going public in 2013. The news pushed its shares up 12 percent to $30.18 — their highest level in more than two years.

“We did what we said we were going to do,” an exultant Jack Dorsey, Twitter’s chief executive, said on Twitter. “Our focus and self-discipline continues to improve.”