(Reuters) - Twitter Inc on Thursday delivered its first quarterly profit and an unexpected return to revenue growth helped by expansion outside the United States, pushing shares in the social network to more than two-year highs.

Overall revenue rose 2 percent in the fourth quarter from a year earlier, handily beating analyst estimates that called for a fourth straight quarter of declines.

Twitter’s previous inability to turn a profit or log consistent revenue growth had confounded investors given its ubiquitous media presence and popularity among celebrities, athletes and politicians such as U.S. President Donald Trump.

Revenue from outside the United States rose 17 percent, making up for an 8 percent decline in U.S. sales. Revenue from Japan rose 34 percent to $106 million, and Chief Financial Officer Ned Segal said Chinese exporters were strong advertisers abroad.

Shares closed 12.1 percent higher at $30.18 after hitting a high of $35.00. Twitter was founded in 2006 and went public in 2013 at $26 a share.

Twitter, which has doubled the number of characters allowed per tweet and made other changes to attract users, said the number of daily active users rose 12 percent.

“Advertisers want eyeballs, so anything Twitter can do to maximize the number of people accessing the platform daily for a good chunk of time allows for better ROI,” or return on investment, analyst Erna Alfred Liousas of Forrester Research said.

Monthly active users grew more slowly, up 4 percent from a year earlier to 330 million. That was flat from the third quarter, which the company blamed in part on seasonal weakness and its purge of fake and spam accounts.

Twitter said revenue was helped by using data to make the targeting of ads more individualized, a process known as machine learning. That raised clickthrough rates, or the ratio of users who click on a specific ad to the number that view it.

The Twitter logo and stock prices are shown above the floor of the New York Stock Exchange shortly after the opening bell in New York, U.S., January 23, 2018. REUTERS/Lucas Jackson

The company also cited higher video ad sales and redesigned ad formats as helping to grow revenue.

“They are showing the right tweets to the right people at the right time, and as you do that, not only do you drive consumers to use Twitter more, but you attract more and more advertisers to want to be on the platform,” analyst Richard Greenfield of BTIG Research said.

Overall revenue was $731.6 million, beating Wall Street’s target of $686.1 million, according to Thomson Reuters I/B/E/S.

The company reported $87 million in data licensing and other non-advertising revenue, up 10 percent from a year earlier. Ad revenue rose 1 percent to $644 million.

Twitter reported a net profit of $91.1 million, or 12 cents per share, compared to a loss of $167.1 million, or 23 cents per share, a year earlier.

Adjusted profit was 19 cents per share, topping analyst expectations of 14 cents per share.

The company said it expects to be “GAAP profitable for the full year 2018,” referring to generally accepted accounting principles.

But analysts were split on what lies ahead for the company.

Twitter needs to attract more new users and is trading at a “lofty premium” given expected earnings, James Cakmak of Monness, Crespi, Hardt & Co said in a client note.

Greenfield said he expected growth for years to come. “This is all about really looking at the potential of revenue growth as they scale and leverage their cost structure,” he said.

Chief Executive Jack Dorsey focused for the past year on tweaking the product he co-founded to attract users, including by trying to limit user harassment. Twitter has also struck deals with media companies for live news and entertainment shows.

Facebook Inc has 2.1 billion monthly users, while Snapchat owner Snap Inc, which does not report a monthly figure, has 187 million daily users.

Dorsey told analysts on a conference call that he was not planning a search to replace Anthony Noto, who is leaving as chief operating officer to become CEO of online lender Social Finance Inc and whose duties have been absorbed by others.

“We’re not going to have to do any backfilling,” Dorsey said.

Shares in Twitter had already surged 47 percent over the past 12 months as of Wednesday’s close, outpacing a 17 percent rise in the S&P 500 Index.

That came even as social media companies are grappling with a regulatory backlash in Europe and the United States over privacy, possible user addiction, hate speech and alleged abuse of by Russia to sway foreign elections.

Twitter’s quarterly profit and rising revenue reignited speculation on Thursday among some analysts that a larger company could try to buy it. The Walt Disney Co expressed interest in 2016, though at the time Twitter shares were trading around $18.