AUGUSTA, Maine — The Maine Public Employees Retirement System is returning millions of dollars it has been managing for public entities in Maine for years, creating windfalls for some but financial headaches for others.

Checks to towns, cities, school systems and public water authorities — some of them for millions of dollars — have been going out to towns and cities in recent months as the retirement system returns some $40.5 million in surplus funds it has been managing for nearly 20 years.

The funds result from the consolidation of approximately 270 retirement programs across Maine in the mid-1990s. Some towns had big surpluses within their systems at the time, which the state has since invested and managed. In some cases, those surpluses have grown.

The refund amounts range from $43.32 in Washington County to more than $6 million for the city of Westbrook.

“It’s just a miracle to us that this amount of money could have been generated by very good investments by the Maine State Retirement System,” Pittsfield Town Manager Kathryn Ruth said of the more than $1.9 million that the town will receive. “Our budgeting in recent years has been very, very conservative.”

Caribou fared even better and has received a $3.4 million refund, according to City Manager Austin Bleess.

“It’s good and it’s bad,” Bleess said Thursday afternoon. “For years that money was sitting there paying our employer [retirement] contribution costs and now we have to fund that out of our operating budget.”

John Milazzo, chief deputy director and general counsel for the Maine Public Employees Retirement System, said many communities, including Caribou, have used their surpluses in the past to cover retirement costs and will now have to make annual payments moving into the future.

“From our perspective, there are no strings attached at all on how the money can be spent,” said Milazzo, who said nearly 100 municipalities are receiving refunds. The money in question is separate from the system’s retirement fund, which is earmarked to pay pensions to past, current and future public employees.

Ruth said the Pittsfield Town Council opted to use about $147,000 to fund the town’s match of retirement funding for the next eight years. The council is considering funding local projects that have languished for years but will use the fund to keep its tax rate stable. The town plans to reinvest most of the refund with the hope of seeing the amount continue to grow.

Ruth said Pittsfield is beginning to put together its budget for the next year and would have had to cut services or raise taxes to balance the books before learning of this refund. The town issued a request for proposals in June for a firm to invest and manage the money.

Bleess said the Caribou City Council decided earlier this year to invest $3 million of the funds into an interest-bearing account at locally owned Aroostook Savings and Loan and use that interest to pay the retirement contributions.

“The council used some foresight,” Bleess said. “It will cover our costs and we may even make a little money on it.”

The account pays 3 percent interest, Bleess said.

“We are investing this on our own,” he said. “Certainly, the rate of return that Maine State Retirement sees in investments outweighs what we can get.”

The remaining $400,000 is going into the city’s regular checking account to assist with its cash flow, the manager said. Bleess said he was notified the funds were coming last fall and the city received them at the end of July.

BDN writer Julia Bayly contributed to this report.

Christopher Cousins has worked as a journalist in Maine for more than 15 years and covered state government for numerous media organizations before joining the Bangor Daily News in 2009.