Shares of BlackBerry (NYSE:BB) recently surged after its fourth-quarter report impressed investors. Its non-GAAP (generally accepted accounting principles) revenue rose 8% annually to $257 million, representing its first quarter of positive growth in years and beating estimates by $14 million. On a GAAP basis, its revenue rose 9% to $255 million.

BlackBerry generated $51 million in net income the quarter, compared to a loss of $10 million a year earlier. On a GAAP basis -- which includes stock-based compensation, acquisition and integration charges, and other one-time expenses -- it reported a net profit of $18 million. Its non-GAAP EPS of $0.11 beat expectations by a nickel.

A businessman points in the same direction as a rising chart made of wood.

Image source: Getty Images.

Those figures indicate that BlackBerry's multiyear turnaround efforts under CEO John Chen are finally paying off. But does this stock still have room to run after rallying about 40% this year?

How BlackBerry made a comeback

BlackBerry was once the market leader in smartphones, but the rise of iPhones and Android devices torpedoed its core business. Between 2009 and 2016, its market share plunged from about 20% to less than 1%.

Chen, who took over as CEO in 2013, decided that the way to save BlackBerry was to phase out its smartphone business and expand its portfolio of higher-margin enterprise software services. BlackBerry stopped producing its own smartphones in 2016 and licensed its brand to the Chinese smartphone maker TCL.

It then nurtured the growth of its software products -- which include BES (BlackBerry Enterprise Service), a platform that lets companies monitor their employees' phones; various cybersecurity services; an enterprise messaging platform; BBM (BlackBerry Messenger); QNX, the world's top embedded OS for connected vehicles; and BlackBerry Spark, a platform for IoT (Internet of Things) devices.

That discontinuation of its hardware business initially resulted in painful sales declines, but killing off the ailing business eventually boosted BlackBerry's year-over-year sales growth again:

Metric

Q4 2018

Q1 2019

Q2 2019

Q3 2019

Q4 2019

Software and services revenue growth (YOY)

13%

14%

1%

10%

14%

Software and services revenue as a percentage of total revenue

91%

89%

92%

96%

96%

Total revenue growth (YOY)

(20%)

(11%)

(14%)

(3%)

8%

YOY = year-over-year. Source: BlackBerry quarterly results. Numbers are non-GAAP.

BlackBerry acquired several smaller security companies, including Good Technology, Encription, and Cylance, to accelerate that growth and expand its ecosystem.

It also spun its licensing business (including its fees from TCL) into a high-margin "licensing, IP, and other" unit that posted 71% year-over-year sales growth last quarter and accounted for 39% of its top line. BlackBerry notably filed patent suits against several companies over the past few years to boost the unit's growth.

A female IT professional checks a tablet.

Image source: Getty Images.

BlackBerry's focus on higher-margin software, services, and licensing fees lifted its gross and operating margins sequentially and annually during the fourth quarter, which indicates that its newfound profitability should be sustainable:

Metric

Q4 2018

Q3 2019

Q4 2019

Gross margin

78.7%

75.9%

81.7%

Operating margin

7.9%

11.8%

22.6%

Source: BlackBerry quarterly reports. Numbers are non-GAAP.

Will BlackBerry's turnaround continue in fiscal 2020?

BlackBerry expects its revenue to rise 23%-27% in fiscal 2020. It expects the gross and operating margins for its core business (excluding Cylance) to hold steady, but it also expects to book nearly $300 million in extra costs ($220 million in operating expenses and $75 million in cost of goods) from its integration of Cylance.

BlackBerry didn't provide earnings guidance for the full year, but analysts expect its non-GAAP EPS to rise 41% to $0.24 per share. But at $10, BlackBerry already trades at 42 times this year's earnings -- so we can't consider the stock cheap relative to its near-term earnings growth.

However, that multiple could contract quickly if BlackBerry's revenue and earnings continue to improve. That recovery could also make the company, which has an enterprise value of just $4.6 billion, an attractive takeover target for bigger tech companies.

Microsoft (NASDAQ:MSFT), which is currently partnered with BlackBerry in the enterprise mobility market, is a natural suitor. BlackBerry's QNX is marginalizing Microsoft's Windows Embedded in the automotive OS market, and its portfolio of enterprise software and services would fit naturally into the tech giant's ecosystem of cloud services.

The bottom line

BlackBerry isn't out of the woods yet, since it's still vulnerable to competition from bigger rivals and a slowdown in enterprise spending. But investors who have an appetite for higher-risk plays should consider buying some shares of BlackBerry before it attracts more attention.