Apple Inc 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.

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.

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.

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.

Apple forecast fourth-quarter revenue of $45.5 billion to $47.5 billion, largely above Wall Street's average estimate of $45.71 billion.