California’s huge public pension funds, CalPERS and the California State Teachers’ Retirement System, have lost more than $5 billion on their fossil fuel investments at a time when some legislators are urging the funds to dump their coal company stocks.

An analysis from the environmental group 350.org found that the two pension funds lost $5.2 billion from June 2014 through June of this year on companies that produce coal, oil and natural gas. And many of those stocks have plunged even further since then, driven down by sinking oil and coal prices.

“It’s important to see that fossil fuels in general, and coal in particular, are risky bets for the pension system,” said Brett Fleishman, senior analyst with 350.org, which promotes fossil fuel divestment as a way to fight climate change. “When folks are saying divestment is risky, we can say, ‘Well, not divesting is risky.’”

A bill from state Senate President Pro Tem Kevin de León, SB185, would direct both funds to divest from companies that get at least half of their revenue from mining coal for power plants. The bill does, however, contain an escape clause. The California Public Employees’ Retirement System and the state teachers’ pension system could keep their coal investments if selling them off would violate their “fiduciary responsibilities” — in other words, produce a huge loss.

Coal companies accounted for $875 million of the funds’ losses in the last year, although the analysis from 350.org includes some companies that would not be covered by de León’s bill. Trillium Asset Management, a firm that works with socially conscious investors, calculated the losses on behalf of 350.org.

“This bill is the right thing to do from both the economic and social perspective,” said Sen. Jerry Hill, D-San Mateo, who co-authored the legislation. “We should be moving to sources of energy, and investments, that are socially responsible and will take us from the 20th century and into the 21st.”

Over the years, CalPERS and the teachers’ pension plan have been the focus of numerous divestment fights — involving tobacco companies, South Africa, Iran and Sudan — with legislators using the funds’ vast holdings to make political or social points. CalPERS is the nation’s largest public pension fund, with more than $301 billion of assets.

CalPERS invests in about 30 coal companies that would be covered by SB185, with a combined market value of $167 million, according to de León’s office. The teachers’ plan holds about $40 million in coal investments that would be affected by SB185.

Despite the losses on fossil fuels, CalPERS earned a 2.4 percent return in the fiscal year that ended June 30. Over the past five years, the fund has earned 10.7 percent.

David R. Baker is a San Francisco Chronicle staff writer. E-mail: dbaker@sfchronicle.com Twitter: @DavidBakerSF