Sales of the iPhone are down, profit slid and revenue grew by just 1 percent — yet Apple still managed to wow investors with its quarterly results on Tuesday.

The Cupertino, Calif.-based tech giant saw its shares surge 4.5 percent, to $218.13, in after-hours trading Tuesday after it delivered better-than-expected third-quarter results — despite continued drops in iPhone sales.

Apple said it eked out a revenue gain of 1 percent, or $53.8 billion, for the three months ended in June, while profit declined for a third straight quarter, down 13 percent, to $10.4 billion.

Driving the profit slump are falling sales of the company’s flagship product, which critics say has been hurt partly by a lack of models that are priced under $1,000. Sales of the once-revolutionary iPhone are down 12 percent from a year ago, to $25.99 billion.

Still, Wall Street cheered the fact that revenue came in $400 million higher than analysts had been expecting, while the company’s earnings per share of $2.18 beat the Street’s $2.09 consensus.

The narrow revenue growth was another welcome relief to Wall Street, which had feared a third-straight down quarter for sales.

The drop in iPhone sales was offset by surprisingly strong growth in demand for gadgets, including Macs, AirPods and the Apple Watch, Apple said. Revenue for its “wearables, home and accessories” segment that contains devices like the Apple Watch and AirPods was $5.53 billion, compared with analysts’ estimates of $4.81 billion.

“You really don’t hear people talk about their phones like they did several years ago,” Hal Eddins, chief economist for Apple shareholder Capital Investment Counsel, said. “The key is that when people want to splurge on a phone, they do it with an Apple product.”

Apple’s earnings come on the heels of a tumultuous three months for the company, which saw the departure of Jony Ive — the visionary designer who is responsible for the look and feel of Apple’s biggest products, including the iPhone, iPad and Apple Watch — as well as a recent tiff with President Trump, who denied a request from Apple to give it a reprieve on tariffs on parts for its new Mac Pro that are made in China.

In a call with investors, Chief Executive Tim Cook dismissed concerns about the Trump administration’s push to have Apple devices built in the US, while vaguely suggesting that the company’s new computer will be made in the States.

“The vast majority of our products are kind of made everywhere; that’s the nature of a global supply chain,” Cook said. “Largely, I think that will carry the day. In terms of the exclusions, we’ve been making the Mac Pro in the US, we’re going to continue doing that. We’re working and investing currently in capacity to do so because we want to continue to be here.”

The company has been dealing with weaker-than-usual demand for iPhones in China, caused in part by a reluctance by Chinese consumers to shell out $1,000 for Apple devices.