MONTREAL - A Quebec Superior Court judge ruled on Wednesday that the City of Montreal went too far when it prevented Auditor General Jacques Bergeron from accessing his budget during a spying scandal.

A year ago, Bergeron discovered that the city was spying on him and had hacked into his email. The city said it was justified in doing so, because it found evidence suggesting the auditor broke internal rules.

The auditor had often ruffled feathers, including when he blew the whistle on the water-meter contract.

Bergeron, suing the city for illegally spying on him, had to face a city government that cut him off from his budget, preventing him from paying his lawyers.

The judge ruled on Wednesday that the city cannot spy on its employees and then use the results to justify their actions. The judge also forced the city to pay for the auditor's legal bills.

The auditor was claiming a victory after the ruling, the city said it was considering an appeal and refused to comment.

When the spying allegations broke out, the auditor was monitoring a hot-line for people wanting to anonymously denounce corruption at city hall.

"The verificateur general, he has a key role to play in the democracy of Montreal and he is an independent," said Real Menard, the borough mayor from Hochelaga-Maisonneuve.

Mayor Gerald Tremblay has since claimed that his administration never spied on political opponents, a claim many in the opposition still refused to believe.