The U.S. economy grew last year at the fastest pace since Ronald Reagan’s presidency, bouncing back with resilience from 2020’s brief but devastating coronavirus recession.

The nation’s gross domestic product — its total output of goods and services — expanded 5.7% in 2021. It was the strongest calendar-year growth since a 7.2% surge in 1984 after a previous recession. The economy ended the year by growing at an unexpectedly brisk 6.9% annual pace from October through December as businesses replenished their inventories, the Commerce Department reported Thursday.

“It just goes to show that the U.S. economy has learned to adapt to the new variants and continues to produce,” said Beth Ann Bovino, chief economist at Standard & Poor’s Global Ratings.

Squeezed by inflation and still gripped by Covid-19 caseloads, the economy is expected to slow this year. Many economists have been downgrading their forecasts for the current January-March quarter, reflecting the impact of the omicron variant. And for all of 2022, the International Monetary Fund has forecast that the the nation’s GDP growth will slow to 4%.

Many U.S. businesses, especially restaurants, bars, hotels and entertainment venues, remain under pressure from the omicron variant, which has kept millions of people hunkered down at home to avoid crowds. Consumer spending, the primary driver of the economy, may be further held back this year by the loss of government aid to households, which nurtured activity in 2020 and 2021 but has mainly expired.

What’s more, the Federal Reserve made clear Wednesday that it plans to raise interest rates multiple times this year to battle the hottest inflation in nearly four decades. Those rate increases will make borrowing more expensive and perhaps slow the economy this year.

Growth last year was driven up by a 7.9% surge in consumer spending and a 9.5% increase in private investment. For the final three months of 2021, consumer spending rose at a more muted 3.3% annual pace. But private investment rocketed 32% higher, boosted by a surge in business inventories as companies stocked up to meet higher customer demand. Rising inventories, in fact, accounted for 71% of the fourth-quarter growth.

“The upside surprise came largely from a surge in inventories, and the details aren’t as strong as the headline would suggest,” Kathy Bostjancic, Oxford Economics’ chief U.S. financial economist, said in a research note.

Arising from the 2020 pandemic recession, a healthy rebound had been expected for 2021. GDP had shrunk 3.4% in 2020, the steepest full-year drop since an 11.6% plunge in 1946, when the nation was demobilizing after World War II. The eruption of Covid in March 2020 had led authorities to order lockdowns and businesses to abruptly shut down or reduce hours. Employers slashed a staggering 22 million jobs. The economy sank into a deep recession.

But super-low interest rates, huge infusions of government aid — including $1,400 checks to most households — and, eventually, the widespread rollout of vaccines revived the economy. Many consumers regained the confidence and financial wherewithal to go out and spend again.

The resurgence in demand was so robust, in fact, that it caught businesses off guard. Many struggled to acquire enough supplies and workers to meet a swift increase in customer orders. With many people now working remotely, shortages became especially acute for goods ordered for homes, from appliances to sporting goods to electronic equipment. And with computer chips in especially short supply, auto dealers were left desperately short of vehicles.

Factories, ports and freight yards were overwhelmed, and supply chains became ensnarled. Inflation began to accelerate. Over the past 12 months, consumer prices soared 7% — the fastest year-over-year inflation since 1982. Food, energy and autos were among the items whose prices soared the most.

Late last year, the economy began to show signs of fatigue. Retail sales, for instance, fell 1.9% in December. And manufacturing slowed in December to its lowest level in 11 months, according to the Institute for Supply Management’s manufacturing index.