The soft iPhone sales were still up from a year ago , and Apple CEO Tim Cook said in a statement that customers "chose iPhone X more than any other iPhone each week in the March quarter."

Shares rose as much 5 percent after hours, as investors digested the company's better-than-expected outlook for the current quarter, and a hefty capital return program.

Apple reported quarterly earnings and revenue on Tuesday that beat expectations, but sold fewer iPhones than expected.

While Apple's iPhone shares were slightly softer than expected, the company managed to make more money than forecast with its services business, and offered Wall Street a generous $100 billion capital return program.

The after-hours stock rally showed Wall Street's relief, after a gloom-and-doom outlook going into the earnings report. Apple has often faced low expectations and managed to surpass them — Apple's EPS results have now beaten consensus 20 of the past 21 quarters.

Apple's new approach to its flagship phone has made it harder than usual to gauge the company's success. Last fall, the company released three new flagship phones, instead of the usual two.

These product releases have put the company's future plans into question, bringing scrutiny to its revenue guidance for the fiscal third quarter. But the company gave sales guidance on the high end of expectations. And in spite of speculation that Apple was winding down iPhone X production, chief financial officer Luca Maestri said on Tuesday that Apple drew down iPhone inventory by 1.8 million units, more than last year.

The average selling price of an iPhone was $728, high for Apple historically but slightly below the $742 Wall Street estimate.

The company has also faced fierce competition in China, a massive market that has homegrown superstars like Huawei and Xiaomi. But Cook noted in the release Apple grew revenue in all of our geographic segments, with over 20 percent growth in Greater China and Japan, thanks in part to adoption of Apple Pay in transit systems there.

Still, Apple's market capitalization remains the highest in any public market, amid optimism around tax cuts and major share buybacks.The company has announced plans to invest in advanced manufacturing in the U.S. and add a new campus. It also has ambitious plans to expand its software and services, and has expanded its reach in content, education and retail. Services revenue hit $9.19 billion during the quarter, well above the $8.39 billion expected by StreetAccount.

Apple's capital return program may have pleased investors but it left slightly less money for those new initiatives (even though Apple's cash pile is still giant.) Apple's cash on hand fell to $267.2 billion in the March 2018 quarter, the lowest total since June. But, Maestri said, tax reform has allowed the company more flexibility on how it uses that cash.

Apple also recently released a new high-end desktop and a new entry-level iPad. Apple sold 9.1 million iPads, in line with StreetAccount's 9.17 million estimate. And it sold 4.08 million Mac computers, just shy of StreetAccount's 4.14 million forecast.

It also released a smart speaker, the HomePod, early this year. Apple's "other products" revenue was $3.9 billion, higher than the StreetAccount estimate of $3.7 billion.

Cook said wearables, like the Apple Watch and AirPods, were up almost 50 percent, and is the size of a Fortune 300 company. He did not disclose an exact figure on the wearables business, but Maestri said wearables and home products accounted for 90 percent of growth in the "other products" category.

While Cook expressed optimism on new markets, he also said he sees a big opportunity to take care of current customers and to convert more mobile phone users to smartphones in areas like India.

"I don't buy the view that the market's saturated," Cook said. "I think the smartphone market is sort of the best market for a consumer product company in the history of the world."