NEW YORK — After gliding through years where stocks mostly just rose, a generation of investors last year suddenly confronted a hard financial truth: Stocks are risky and can plunge at any moment.

For older investors, the nearly 20 percent drop in the S&P 500 index from late September through Christmas Eve was a reminder of the fear that gripped markets during the 2008 financial crisis, though not as bad. But for many investors in their 20s and early 30s, it was the first test of their mettle since they opened 401(k) and brokerage accounts.

So how did they do? The answer is crucial because these younger savers are on the hook to pay for more of their retirements than their parents or grandparents.

The fear was that many would panic at their first brush with a severe downturn, sell their stocks and lock in the losses. Investing is an area where many experts say a participation trophy is an unquestionably good thing. Given enough years, stocks have gone on to recover from every one of their past declines.

Early indications are that millennial investors generally avoided panic. And not only are they still participating, but many embraced the volatility and saw it as an opportunity to buy more stocks at lower prices, according to data from brokerages.

At Fidelity, for example, millennial investors put in twice as many buy as sell orders for stocks and stock funds during the last three months of 2018, when the S&P 500 plunged 14 percent for its worst quarterly performance in nearly seven years.

They were actually more aggressive about buying stocks than they were a year earlier, at the end of 2017, when the S&P 500 closed out one of its strongest and calmest years in decades.

Older generations of investors also embraced the tumult in recent months and picked up their buying activity for stocks, though they were not as aggressive as millennials. Baby boomers had roughly 1.3 buy orders for every sell order during last year's fourth quarter, for example. The data cover Fidelity's 20.8 million retail brokerage accounts.

The decisions did not come stress-free. Consider Dr. Marcus Harris, 35, an internal medicine practitioner in the Houston area.

Last summer, when stocks were setting record after record, Harris felt confident that he would be able to handle a severe downturn, even though he had yet to experience one in his five years of investing.

When the market started skidding on worries about a slowing economy and President Donald Trump's trade war with China, though, Harris acknowledges he felt some trepidation.

He had set his phone to notify him when some of the stocks he owns hit certain prices, both on the high and the low end. At work, as the S&P 500 careened lower in December to its worst month in nearly a decade, he got used to hearing often from his phone.

"It was probably five times a day," he said. "Ding! This stock has hit your low. Ding! That stock hit your low."

"It was a little scary, looking at my retirement account saying, 'Man, that's a lot of salary gone,' " he recalled. Harris eventually turned off the notifications. But he also said that he knew he had many years to go before he needed to use the money.

He ended up putting more money into stocks late last year, hoping to buy low. "I got age on my side," Harris said. "This is a 30-year plan."

The reaction was similar for many clients of Charles Adi, financial adviser at Blueprint 360 in Houston.

Before the downturn, Adi had discussed many times with his clients market volatility and the importance of sticking with an investment plan. But he got more worried calls than he was expecting as markets tumbled.

"You think your clients are going to act one way because you have these conversations, and they reassure you they know the game plan, but you really don't know what's going to happen in the moment," he said. "More often than not, the conversation I had was: 'You told me there were going to be some fluctuations, but I didn't understand what you meant. Are we going to change the plan?' "

In the end, most held steady. Only four of his clients moved their investments out of stocks and into cash, and three of them were older.

For many of his younger clients, he suggested viewing the drops as an opportunity to double down on stocks they were familiar with and had already reaped gains from, such as Netflix, Amazon and marijuana stocks. Many agreed.