Assets in 529 college-savings plans are soaring as American families search for ways to offset rising college costs and crushing student-loan debt.

As of year-end 2012, investors had more than $166 billion in the college savings accounts, up 25% in a year and nearly 40% in the last two years, according to a study by Morningstar Inc.

The increase stems partly from investment gains, particularly in the stock market. But the rise in 529 assets far outdistances the improvement in most stock indexes, such as the Standard & Poor’s 500, which was up a bit more than 13% from 2010 to 2012.

Investor interest in 529s has been stoked partially by states trying to make the plans more attractive.

College plans carry higher fees than comparable mutual funds. But the gap generally has lessened in recent years as states have tried to rein in 529 costs.

The expense ratio of the average 529 plan is 1.15%, according to Morningstar. The average 529 plan is 0.35% higher than comparable mutual funds.

The gap is up from the 0.31% in 2011 but down from 0.40% in 2010, according to the fund research firm.

The picture is brighter in California, where fees have dropped significantly since the state switched to a low-cost 529 manager in late 2011.

The average expense ratio of California’s ScholarShare program is 0.36%, according to Morningstar. That’s down from 0.56% in August 2011, while Fidelity Investments ran the plan. ScholarShare is now managed by TIAA-CREF.

Ranked against other states, California has the 11th-cheapest plan, according to Morningstar. Under Fidelity, it was No. 27.