|By Julia Love and Anya George Tharakan

|By Julia Love and Anya George Tharakan

|By Julia Love and Anya George Tharakan

(Reuters) - Apple Inc <AAPL.O> sold more iPhones than Wall Street expected in the third quarter and estimated its revenue in the current period would top many analysts' targets, soothing fears that demand for the company's most important product had hit a wall.

Its shares rose 7 percent in after-hours trading.

The world's most valuable publicly traded company said it sold 40.4 million iPhones in the third quarter, down 15 percent from the year-ago quarter but slightly more than the average analyst forecast of 40.02 million, according to research firm FactSet StreetAccount.

IPhone sales dropped for the second straight quarter, pushing down Apple's total revenue 14.6 percent in the fiscal third quarter, ended June 25.

Demand for Apple's phones has waned in China, partly because of economic uncertainty there, and has also slowed in more mature markets as people tend to hold on to their phones for longer. The sales slump has stoked concerns about whether the tech leader can continue to deliver profits at the level Wall Street has come to expect.

"China was a major letdown," said Patrick Moorhead, an analyst at Moor Insights & Strategy. "Samsung and Huawei are much more competitive now than a year ago and the Chinese economy is not doing well at all."

Moorhead said, however, that increased services revenue - which includes the App Store and iCloud - was a "very big bright spot for Apple."

Chief Financial Officer Luca Maestri told Reuters in an interview that Apple's performance had topped his expectations in a quarter weighed down by tough foreign exchange rates and difficult comparisons with blockbuster iPhone 6 sales from the previous year.

Customer demand "was better than what is implied in our results and better than we had anticipated," he said.

Sales of the iPhone fell last quarter for the first time since the gadget's release in 2007, dropping 16.3 percent. Maestri projected the gadget's average selling price to rise in the September quarter.

The iPhone drives about two-thirds of Apple's total sales. Apple Chief Executive Tim Cook said during a call with analysts that the iPhone SE, a cheaper, four-inch (10 cm) phone released this year, was extending the range of people able to buy Apple phones.

"It's opening the door to customers we weren't reaching before," he said.

Sales in Greater China, once touted as Apple's next growth engine, decreased 33.1 percent, compared with a 112.4 percent growth in the year-earlier quarter and a near 26 percent fall in the second quarter.

Maestri attributed the drop to channel inventory reduction in the nation, foreign exchange headwinds and a general downturn in the Chinese economy.

"It is very clear that there are some signs of economic slowdown in China, and we will have to work through them," he said.

Adding to Apple's woes in China, the company's stores for books and movies went dark earlier this year. Cook said Apple was working with regulators to restore the services but played down the financial impact of the outage, saying the stores yielded less than $1 million in revenue during the short time they were on the market.

"It’s not a revenue-related issue," he said. "This is a service we want to provide our customers."

Apple's services business, which includes the App Store, Apple Pay, iCloud and other services, generated nearly $6 billion in revenue, up 18.9 percent from the previous year.

As iPhone sales level off, Apple is attempting to use such services to wring more revenue out of its existing base of users. The business emerged as Apple’s second largest after the iPhone for the first time in the second quarter, eclipsing gadgets such as the iPad and the Mac.

That shift bodes well for Apple because gross margins on services are better than the average for the rest of the company, Maestri said.

"It’s a great business because it is recurring in nature and more linked to our installed base," he said.

Maestri touted music as an example of one successful service, saying the growth of the Apple Music streaming service had more than made up for declines in digital downloads. To redouble its momentum in music, Apple purchased rights to the next season of popular series Carpool Karaoke, CBS Television Studios announced on Tuesday.

India was one of the rare bright spots, with 51 percent growth in iPhone sales, as Apple expands into emerging markets.

"India is now one of our fastest growing markets ... We're looking forward to opening more retail stores in India down the road, and we see huge potential," Cook told analysts.