The unanimous high court ruled 9-0 that the government is not obliged to return funds to the public sector unions.
"The government was not under a fiduciary obligation to the plan members, nor was it unjustly enriched by the amortization and removal of the pension surpluses," Justice Marshall Rothstein writes for the court.
The complex 73-page ruling ends a long legal battle that dates back to the 1990s in which unions representing public servants, the RCMP and the military wanted the surplus money returned.
The unions and professional associations were attempting to overturn an Ontario Court of Appeal ruling that said they weren't entitled to the money.
The unions argued that the government improperly took their money, from the mandatory, defined benefit plans.
The plans are among some of the most handsome pensions in the country.
Meanwhile, many private sector companies are struggling with underfunded pensions.
"The plan members' interests are limited to their interest in the defined benefits to which they are entitled under the plans," writes Rothstein.
The ruling comes as the government is attempting to slay the deficit and control public spending.
If the unions had won their appeal, it could have forced a massive federal expenditure that could have affected its long-term economic planning.
The ruling essentially affirmed the actions taken by the former Conservative and Liberal governments in the 1990s to take surplus funds from what had become lucrative public pension funds and apply them to country's deficit.
The total surpluses of plans for the three groups of federal employees — public servants, the Canadian Forces and the RCMP — had grown to $30.9 billion by 1999, the ruling states.
The ruling says the government began in 1990-91 to "amortize" the actuarial surpluses in its Superannuation Accounts.
"The effect of this 'amortization' was twofold: it reduced the government's annual budget deficit (or increased the annual budget surplus) by reducing annual pension expenditures, and it brought the government's net debt down by reducing the net pension liabilities to an amount closer to the actuarial estimates of the government's future pension obligations."
In 2000, the Liberal government passed a new law that changed how the pension funds were collected, managed and distributed.
Under the new law, the government debited $28-billion directly, "thereby reducing the actuarial surplus in those accounts."
The unions failed in their bid to get that money back.
The Supreme Court ruled "they did not suffer any detriment as a result of the government's accounting treatment" and that the government "did not expropriate any property of the plan members."
Gary Corbett, president of the Professional Institute of the Public Service of Canada, said the union was disappointed by the decision.
But he acknowledged that the decision would not diminish the pension benefits that the union's 60,000 members were entitled to receive.
"If this had been a case involving the private sector, an employer would never have gotten away with this action," said Corbett.
Treasury Board Minister Tony Clement used the Supreme Court's decision to take a shot at the former Liberal government of Jean Chretien.
"This case concerned a decision made by the previous Liberal government in 1999; had the lawsuit been successful, Canadian taxpayers' would have been left with an enormous expense," he said in a statement.
He said the Conservative government is making the federal pensions more sustainable by making them "more in-line with the private sector by making public service employees pay an equal contribution amount."
Also on HuffPost