The Supreme Court ruled unanimously Thursday that public employees are protected from retaliation when they testify in court about misconduct they observed on the job, a decision important to millions of government workers.

Public employees who are called to testify are protected by the First Amendment just as other citizens are and should not have to choose between “the obligation to testify truthfully and the desire to avoid retaliation and keep their jobs,” wrote Justice Sonia Sotomayor.

The decision clarified previous rulings in which the court has said that public employees have free-speech rights when they are acting as citizens, not when they are testifying about what they learned in their jobs or are required to speak because of their specific duties.

The justices said lower courts had read those decisions too broadly.

“The mere fact that a citizen’s speech concerns information acquired by virtue of his public employment does not transform that speech into employee — rather than citizen — speech,” Sotomayor wrote.

Stephen Kohn, executive director of the National Whistleblower Center, said the ruling “will have a direct and major impact on the willingness of public employees to expose corruption in government.”

He added: “The right of every American citizen to truthfully testify about criminal activities, including fraud in government contracting, is a cornerstone to a democracy.”

The case involved Edward Lane, who Alabama Attorney General Luther J. Strange III said at oral argument was key to exposing “one of the most egregious public corruption situations in Alabama’s history.”

Lane, director of a youth training program at Central Alabama Community College, discovered in 2006 that a state legislator, Rep. Suzanne Schmitz (D), had arranged a no-show job for herself with the program.

Lane fired her for nonperformance.

After she was terminated, the FBI began investigating. Lane was subpoenaed to testify, first before a grand jury and subsequently at two criminal trials. The first ended in a mistrial, but Schmitz was convicted in the second.

In between the trials, the community college’s then-president, Steve Franks, said cuts in the program’s budget required layoffs, and he fired 29 probationary employees with less than three years of service. Franks said he then discovered many of the employees were not probationary and hired them back.

Lane was one of only two not rehired, and he filed suit, saying the action was retaliation for his testimony.

Lower courts did not rule on whether Lane was right. Instead, relying on the Supreme Court’s previous rulings, a district judge and then the U.S. Court of Appeals for the 11th Circuit said Lane’s First Amendment complaint could not go forward because he was not testifying in his role as “citizen.”

That was a mistake, Sotomayor said.

The court has always recognized the “special value” of speech by public employees precisely because they gain valuable knowledge through their employment, she wrote.

“It would be antithetical to our jurisprudence to conclude that the very kind of speech necessary to prosecute corruption by public officials — speech by public employees regarding information learned through their employment — may never form the basis for a First Amendment retaliation claim,” she said.

The court’s decision did not address public employees whose job requirements include testifying in court, such as police officers and laboratory analysts, Justice Clarence Thomas noted in a concurring opinion joined by Justices Antonin Scalia and Samuel A. Alito Jr.

The decision, while important going forward, may not help Lane much.

Sotomayor said the lower courts were right that Franks could not be sued in his individual capacity. Public employees are generally protected against suit unless they have violated the law or a clearly established constitutional right.

“But because the question was not beyond debate at the time Franks acted, Franks is entitled to qualified immunity,” the court held.

But the court sent the case back for consideration of whether Lane might be able to bring a suit against the college and its current president in her official capacity.

The case is Lane v. Franks.