SAN FRANCISCO (Reuters) - Twitter Inc's monthly active users rose a better-than-expected 24 percent in the second quarter as the online messaging service mostly succeeded in stemming a dwindling pace of growth, sending its shares soaring almost 30 percent after hours.

Twitter, which has battled to reverse a steady decline in its once-heady pace of user growth, grew users to 271 million, still dwarfed by rival Facebook Inc's 1.3 billion. Timeline views, a measure of the engagement of its users, also exceeded expectations with a 15 percent increase.

On Tuesday, Twitter reported a 124 percent jump in quarterly revenue to $312 million, beating Wall Street's expectation for $283.1 million. Its shares rose 26 percent to $48.80 in extended trading, from a close of $38.59 on the New York Stock Exchange.

Try Newsweek for only $1.25 per week

Wall Street had been divided on whether Twitter can transform itself into a mainstream Internet platform on the same scale as Facebook. Some investors argue its reported user numbers do not fully reflect engagement, particularly with media viewers. Others say its inherently complex format deters wider adoption.

At its peak in December, Twitter enjoyed a $46 billion market capitalization on just $665 million of revenue in 2013, making it one of the world's priciest stocks.

User growth has stagnated since Twitter went public to much fanfare in November. Chief Executive Officer Dick Costolo has said that tweaks to Twitter's product would result in better user engagement, and has asked Wall Street for time to show improvement.