By Heather Haddon

The coronavirus is still weighing on Starbucks Corp.

The coffee giant on Tuesday reported its steepest earnings per share losses in more than a decade as a result of lower sales and higher costs stemming from the pandemic. Global same-store sales plunged by 40% in the quarter ending in June, and the Seattle-based chain reported a loss of $704 million, down around 17% from a year earlier.

But that was better than many analysts expected given the severity of the blow the pandemic has dealt to the Starbucks, first in China, then across Asia, Europe and the U.S. The chain said it expects the worst effects of the virus to moderate in its current quarter.

Shares of Starbucks rose 3% to $77 in after-hours trading.

Big chains have generally performed better than independent restaurants during the pandemic due to their drive-throughs and established takeout operations. But chains have also notched big sales hits. McDonald's on Tuesday said its same-store sales fell 24% globally in its most recent quarter, and it expects the virus and resulting economic downtown to depress consumer spending for some time.

Starbucks was early among chains to close stores as a result of the coronavirus and to pay employees bonuses or allow them to stay home if they weren't comfortable working during the pandemic. It said it lost $3.1 billion in sales during the third quarter due to store closures, limited hours and fewer customer visits.

Starbucks said 96% of its company-owned U.S. stores are now open with at least to-go and limited dine-in service. The company has beefed up delivery and pickup services that it intends to keep. It also is building more to-go only stores in the U.S.

The coffee chain said it expects global same-store sales declines of 12% to 17% for its fourth-quarter and full year and for revenue to decline by 10% to 15% compared with the previous quarter. Starbucks said it expects earnings of 6 cents to 21 cents a share for its fourth quarter.

For the third quarter, spending on worker pay, benefits and protective equipment hurt margins. The chain's Americas segment reported operating losses of $405 million during the quarter. The company said it had $4.2 billion in sales in the quarter, down 38% from the prior year's period but better than expectations of analysts' polled by FactSet.

Write to Heather Haddon at heather.haddon@wsj.com