(Karen Bleier/AFP/Getty Images)

The Supreme Court ruled Tuesday for an officer with the Paterson, N.J., Police Department who was demoted because his bosses thought — mistakenly, as it turned out — that he was campaigning for a challenger to the mayor.

The court ruled 6 to 2 that the actions of then-Police Chief James Wittig in disciplining Officer Jeffrey Heffernan violated the officer’s First Amendment rights.

Justice Stephen G. Breyer acknowledged that it was an unusual case because Heffernan was not actually exercising his free-speech rights — Heffernan claims he was picking up a campaign sign for mayoral candidate Lawrence Spagnola on behalf of his bedridden mother.

Lower courts had thrown out Heffernan’s lawsuit against his superiors because he was not actually campaigning for Spagnola.

But Breyer said the key to the case was not Heffernan’s actions but the motivation of the police chief, whose loyalty was to the incumbent mayor, Jose Torres.

“The government’s reason for demoting Heffernan is what counts here,” Breyer wrote. “When an employer demotes an employee out of a desire to prevent the employee from engaging in political activity that the First Amendment protects, the employee is entitled to challenge that unlawful action.”

With a few exceptions, such as neutral laws prohibiting public employees from engaging in partisan activities, the Constitution protects an employee’s freedom to participate in political activity.

Ruling for Heffernan sends a message to other employees, Breyer wrote.

“The constitutional harm at issue in the ordinary case consists in large part of discouraging employees — both the employee discharged (or demoted) and his or her colleagues — from engaging in protected activities,” Breyer wrote. “The discharge of one tells the others that they engage in protected activity at their peril.”

Breyer was joined by Chief Justice John G. Roberts Jr. and Justices Anthony M. Kennedy, Ruth Bader Ginsburg, Sonia Sotomayor and Elena Kagan.

Justices Clarence Thomas and Samuel A. Alito Jr. dissented.

“Federal law does not provide a cause of action to plaintiffs whose constitutional rights have not been violated,” Thomas wrote.

He said it was “not enough for the city to have attempted to infringe his First Amendment rights. To prevail on his claim, he must establish that the city actually did so.”

At oral argument, the case was described as something like a law-school hypothetical.

Heffernan was a detective in the police department, assigned to a division headed by the police chief. One day, on his own time, he went to Spagnola’s headquarters to pick up the sign for his mother before the 2006 election.

Heffernan was a close friend of Spagnola, who also was a former police chief, and other police officers observed the interaction.

The next morning, Heffernan was called into Wittig’s office and demoted to patrol officer. He was told it was because of his “overt” involvement in a political campaign.

The case bounced around lower courts for years; Heffernan won once, only to have the judgment overturned. Finally, the U.S. Court of Appeals for the 3rd Circuit ruled that Heffernan could not receive damages for a First Amendment violation when he had not actually exercised First Amendment rights.

The legal battle is not over. Breyer noted that there were suggestions that Heffernan violated a different, neutral policy preventing officers from overt involvement in any political campaign. That is a matter for the lower court to figure out, Breyer said.

The case is Heffernan v. City of Paterson .