By Josh Mitchell and Suzanne Kapner

Americans' shopping surpassed pre-pandemic levels last month, but the U.S. economy still faces threats as it digs out of a severe recession.

Retail sales -- reflecting what households spent at service stations, stores, restaurants and online -- rose 1.2% in July, the Commerce Department said Friday. That marked the third consecutive monthly gain as the U.S. strived to reopen its economy as much as possible despite the challenges posed by the coronavirus pandemic.

After accounting for seasonal factors, sales were 1.7% higher compared to February, the month before the pandemic shut down much of the economy. Consumers last month boosted spending on electronics and appliances, health products and restaurant meals.

More recent evidence suggests households moderated spending in certain areas. One factor: the July 31 expiration of an enhanced unemployment benefit. That benefit, authorized in the Cares Act passed by Congress in March, had boosted jobless workers' weekly income by $600 a week, and many households spent it.

Facing a congressional deadlock over a new stimulus plan, President Trump has acted to replace the payments with a $300-a-week benefit, but it isn't expected to reach workers for weeks.

"There's a lot of talk about the recovery as if they've declared the recession dead already," said Amy Crews Cutts, head of the consultancy AC Cutts & Associates. "I think we are not clear from a recession, and the stops and starts that are happening in the economic opening at the state level are showing a fragility in the economy."

Many economists expect the economy to rebound this quarter after gross domestic product fell 9.5%, or 32.9% at an annual rate, in the second quarter. Economists expect output to grow at an 18.3% annual rate in the third quarter, according to a Wall Street Journal survey.

Other data suggest the economy is growing. Industrial production, a measure of output at factories, mines and utilities, rose 3% in July from June, the Federal Reserve said Friday, after a 5.7% rise in June.

The economy has added millions of jobs in the past three months, including 1.8 million in July. Initial jobless claims, a proxy for layoffs, fell below 1 million last week for the first time since March. Still, layoffs remain exceptionally high, employment is down by nearly 13 million from February, and the jobless rate stood at a historically high 10.2% in July.

In the world's largest economy, consumers are paramount. Their spending reflects more than two-thirds of economic demand. Retail spending, which excludes costs like utilities and rent, represents a big chunk of all consumer spending.

A rise in coronavirus infections in several big states earlier this summer prompted a new round of restrictions on businesses and spooked many consumers back into their homes. The prospect of schools moving teaching online this fall may also undermine back-to-school spending.

"Many households are now being more cautious now that enhanced unemployment benefits have dried up," said Neil Saunders, a retail analyst for the research firm GlobalData.

Only 36% of consumers tracked by GlobalData spent more or the same amount on retail purchases during the first week of August as they did the same week a year ago. That is down from 57% who did so during the last week of June. Separate data show consumers cut credit-card spending in stores in late July and early August, compared with year-earlier levels, according to data from Earnest Research. Restaurant spending also lost momentum in recent days, OpenTable data show.

The data firm Affinity Solutions, which analyzes credit-card spending, said overall retail spending, excluding car purchases, rose in early August compared to July, though consumers cut back on certain categories such as furniture, health-care products and construction materials.

Foot traffic to retail stores declined six weeks ago, coinciding with the receipt of the last batch of stimulus checks, a separate part of the pandemic relief unrelated to the added unemployment benefits, according to Aneta Markowska, the chief financial economist at Jefferies Group LLC. The firm parses data from location-tracking company SafeGraph Inc., and since then has found that foot traffic has remained fairly steady, despite the end of the additional unemployment benefits.

Shawn Hall spent her $1,200 stimulus check as soon as she received it in April on bills and rent. Since the pandemic started, the 48-year-old Charlotte, N.C., resident has been earning less as a self-employed education consultant, and she is hoping Congress passes another round of stimulus spending to help her make ends meet. Meanwhile, she has cut back on dining out and Starbucks lattes, opting to make coffee at home.

The $600 weekly unemployment benefit expired July 31. That had funneled $250 billion to families this spring, according to a Wall Street Journal analysis. Last week, President Trump announced a series of executive actions that, among other things, would continue to provide an enhanced jobless benefit to Americans.

Even with that action, Ms. Markowska expects spending to decline in August since it could take weeks to get the checks out. "Even though the payments will be retroactive, it will be too late to salvage August," she said.

Consumer spending has held up. One big factor is that aggregate household income has actually grown since the pandemic began in March, boosted by federal stimulus checks of as much as $1,200 for individuals and the enhanced unemployment benefit.

Many households have used that money to pay bills and build up savings, with the personal savings rate soaring. As the pandemic-related shutdowns have extended for months, consumers have started to spend some of their money, particularly on big-ticket items and projects like refurbishing their homes.

Business has been steady for Joff Masukawa, a self-employed life-sciences consultant in his 50s from Washington, D.C. He bought a 1950s ranch-style house in Laurel Park, N.C., in May so that his mother could move out of a senior-living community. He is renovating the house and in July bought a refrigerator, stove, dishwasher and microwave.

Mr. Masukawa said he is still spending a bit less than he was before the pandemic. "What I'm not buying are clothes," he said. "I'm not buying anything going out to eat. I'm not going to bars. The only entertainment we spend money on is really cable-internet service and then the various streaming things."

He also suspended his gym membership and, for exercise, recently bought the Mirror, a product that displays an exercise routine.

--David Harrison contributed to this article.

Write to Josh Mitchell at joshua.mitchell@wsj.com and Suzanne Kapner at Suzanne.Kapner@wsj.com