SAN FRANCISCO>> Apple has had plenty of challenges to start the year. The Apple Watch has been altered by patent lawsuits, the App Store has come under fire from developers, and the iPhone has faced renewed competition in China.

Topping it all off, the company was recently dethroned as the undisputed king of the stock market when Microsoft replaced it as the world’s most valuable public company.

But on Thursday, the tech giant showed the versatility and strength of its business, reporting that sales rose 2% to $119.58 billion during the three months that ended in December.

It was the first quarterly revenue increase for Apple in a year and helped the company deliver $33.92 billion in profit during the period, a 13% increase from a year earlier.

The results showed that Apple had the ability to overcome a slowdown in device sales by getting its enormous customer base to buy more apps and services, such as Apple Music. The company said sales of software and services rose 11% to $23.12 billion during the period. Shares of Apple fell about 1% in after-hours trading, even though the company exceeded analysts’ expectations for $117.99 billion in sales.

Although the iPhone and iPad are more than a decade old, Apple said the number of its devices in use around the world last year had increased by 200 million from the 2 billion it reported a year ago. Investors watch that figure closely because as iPhones, iPads and Apple Watches proliferate, more people are willing to pay Apple for things such as cloud-computing storage.

The iPhone, which accounts for more than half of Apple’s annual revenue, was the only Apple device to post an increase in sales during the quarter. Apple’s release of a new, titanium version of the device last year helped it increase the number of smartphones it sold by 5 million, according to Canalys, a market research firm. The uptick lifted iPhone sales 6% to $69.7 billion.

But sales of iPads and wearables such as Apple Watches declined, and Mac sales were flat.The company’s total device sales were almost the same as a year earlier at $96.46 billion.

In China, Apple’s second-biggest market, the company is navigating a slowing economy and increased competition. Chinese consumers are cutting back on spending, while Huawei, China’s cellphone giant, has released a smartphone with high-quality cameras and lower prices than Apple. To keep pace, Apple has begun discounting iPhones in China.