401(k) millionaires reach an all-time high. Here’s the No. 1 thing most Gen Xers and boomers did to get there.

Retirement-account balances reached record highs in the second quarter, propelling more investors into the 401(k) millionaire club, according to Fidelity Investments.

The ranks of 401(k) millionaires reached an all-time high of 595,000 individuals in the second quarter, Fidelity said. The median balance among the millionaires was $1.4 million.

Fidelity said this group of investors had been saving for an average of 25 years — having weathered market ups and downs from the dot-com crash, to the 2008 financial crisis, to the COVID-19 pandemic.

“This population of savers is a great example that saving for retirement is a marathon, not a sprint,” said Mike Shamrell, vice president of thought leadership at Fidelity. “The vast majority are baby boomers and Gen X-ers, and they’re really good examples of taking a long-term and consistent approach to retirement savings. There wasn’t some magic stock pick that put them into this category — it was just really consistent savings.”

The stock market’s performance also buoyed average 401(k), 403(b) and IRA balances to new record highs in the second quarter. The S&P 500 SPX gained 10.9% in the second quarter, recovering from the downturn of the first quarter.

Despite the market volatility seen at the start of the second quarter, the quarter’s performance overall pushed the average 401(k) balance up by 8% from a year earlier, to $137,800. The median 401(k) balance — the midpoint between the highest and lowest balances — was $32,300. The average 403(b) balance increased 9% to $125,400, and the median 403(b) balance was $31,399. The average IRA balance increased 5% over that time to $131,366, while the median balance was $11,198.

“Even during periods of turbulence, the majority of savers are wisely making the decision to stay the course and not make sudden changes to their retirement investments,“ said Sharon Brovelli, president of workplace investing at Fidelity. ”This diligence and focus on long-term retirement goals contributed to this quarter’s retirement-balance rebound, demonstrating the importance of staying calm and not overreacting to market changes.”

Only 5.5% of retirement savers made a change to their 401(k) asset allocation in the second quarter. Of this group, more than 8 in 10 made only one change, Fidelity said.

“We want to encourage people not to make changes in response to short-term market events,” Shamrell said. “When the stock market faces uncertainty, it often recovers very quickly, which we saw in the second quarter. By staying the course, people were able to take advantage of those gains, and that underscores why people should focus on long-term goals.”

The total average 401(k) savings rate for the second quarter remained consistent with the first quarter, when it hit a record high. This was a result of an employee-contribution savings rate of 9.5% and an employer-contribution rate of 4.8%. At a total of 14.2% in the second quarter, the number remains close to Fidelity’s suggested savings rate of 15%.

Although average IRA contributions have remained steady over the past year at $2,223, contributions for both Gen X-ers and baby boomers are on the rise — increasing by 25% for Gen X-ers and 37% for baby boomers from the year-ago quarter.

“With the market volatility experienced earlier in the quarter, it’s understandable that some retirement savers may feel uncertain about how their balances are being impacted,” said Robert Mascialino, president of wealth at Fidelity. “However, we’re seeing solid 401(k) contributions and more people adding to their IRAs — especially baby boomers and Gen X, who are continuing to prioritize retirement. It’s encouraging to see customers focus on the long game when it comes to investing for retirement.”

The share of workers with outstanding loans on their Fidelity 401(k) accounts increased in the quarter to 19%, up from about 18% in the year-ago quarter, Shamrell said. The percentage of people initiating a new 401(k) loan was about 2.8%, down from 3% a year earlier.

“This is an area we’re keeping our eye on and really underscores the importance of emergency funds,” Shamrell said. “A lot of times, people will take a loan for a financial emergency such as a car breaking down or a pet medical expense. That indicates the need for creating emergency funds so you don’t have to tap your retirement savings to get through that need.”