BELFAST, Maine — Last year, the Maine Public Employees Retirement System sent to municipalities and school districts across the state more than $40 million in surplus retirement funds that the government had been holding onto for decades.

One $2.98 million check, sent last summer to the two-town Regional School Unit 20, initially took district officials aback by its unexpectedly large size. After the surprise wore off, the windfall started a debate among the nine communities that previously had made up RSU 20 before disputes over education and taxation led to the withdrawal of seven municipalities. Each of the communities, including Belfast, wanted its fair share of the surplus money but initially could not agree on how much that would be.

But the debate appears to be over, an attorney for Regional School District 71 told the Belfast City Council Tuesday night, after the parties made it through a marathon nine-hour mediation session in front of a retired Superior Court justice earlier this month. According to the terms of the mediated agreement, RSU 71 — Belfast, Belmont, Morrill, Searsmont and Swanville — and the Northport Municipal School Department will get $2.5 million. RSU 20 — Searsport and Stockton Springs — will get almost $500,000, and Frankfort will get $21,000.

“We have settled it, hopefully,” Kristin Collins told the council. “One thing that did definitely come up in the mediation was just how long and how convoluted the litigation process would be about this [if the matter was not settled out of court]. The Superior Court judge was very adamant that this would be a two to three year case, and would possibly cost $400,000 in legal fees.”

RSU 20 was formed in 2008 after the passage of the school consolidation law. At that time, the former SAD 34, made up of Belfast, Belmont, Morrill, Northport, Searsmont and Swanville, and the former SAD 56, made up of Frankfort, Searsport and Stockton Springs, united to form one sprawling district. Board members for the new school district were not aware of the funds that the Maine Public Employees Retirement System had been investing since the 1980s and 1990s, when school districts had their own individual retirement accounts with the state.

Retirement funds were consolidated in 1996, but the individual accounts still had varying amounts of money left in them — including a lot of money in the account for SAD 34, Collins said, and a little money in the former SAD 56 account.

“In 2008, RSU 20 was formed, and no one ever paid attention to those funds, which have been gathering interest for all these years,” Collins said.

Frankfort was the first town to withdraw from RSU 20, followed in the fall of 2014 by Belfast, Belmont, Morrill, Northport, Searsmont and Swanville. Voters from five of the communities decided to form the new RSU 71, and Northport voters chose to be an independent school district.

Tony Bagley of Searsport, the RSU 20 chair and a longtime school board member, said that the intact but embattled district could really have used the money it didn’t know it had.

“That was the most frustrating part,” he said Wednesday. “The old RSU 20 as a whole could have used the money to offset tax increases. … Everybody was upset with the rising costs of RSU 20 tax increases, and there was something there to soften the blow that the board was never apprised of. That’s very frustrating as board chairman.”

Bagley said that he attended the long mediation session, held Thursday, Feb. 4, and that he feels it had a positive resolution.

“We came to a mutual agreement,” he said of RSU 20 and RSU 71 officials. “We’re happy with it.”

The resolution still needs to be approved by the RSU 20 board of directors, and it is on the agenda for the next meeting, Bagley said. RSU 71 directors already have approved it, according to Collins. On Tuesday night, the Belfast City Council voted in favor of signing a release to accept the proposed settlement, as each of the other four RSU 71 communities will need to do before the money can be disbursed, Collins said.

The RSU 71 board members have decided that the money the district is getting — about $2 million — will be put into a reserve account to continue to fund the public employees retirement system, as long as it lasts.

Collins said the school district needs to put in $300,000 or $400,000 per year to fund the retirement system, and so the windfall ought to reduce the tax assessments of the member towns by that amount of money for as many as seven years.

“That’s what they felt was going to be a reasonable thing to do — to promise it would go to tax relief rather than fund some new program,” Collins said of the RSU 71 board.

Over at RSU 20, Superintendent Chris Downing said that the Maine Public Employees Retirement System money also will be used to help the two towns with tax assessments for the schools.

“That is exactly what it should be used for,” he said. “I think that when we all sat down and started working on it, it turned out to be a win-win situation for everybody. Fair and equitable. Now we can move on.”