A journalist who disclosed details of a secret CIA operation cannot shield his source when he testifies at the trial of a former federal agent charged with leaking classified information, a divided U.S. appeals court ruled Friday.

The 2-1 ruling by a 4th U.S. Circuit Court of Appeals panel reversed a judge’s ruling limiting the scope of New York Times reporter James Risen’s testimony at former CIA officer Jeffrey Sterling’s trial. The judge had said Risen could be questioned about the accuracy of his journalism but could not be forced to divulge any confidential sources.

That might be OK in a civil trial, but not in a criminal case, the appeals court said.

Risen “can provide the only first-hand account of the commission of a most serious crime indicted by the grand jury — the illegal disclosure of classified, national security information by one who was entrusted by our government to protect national security, but who is charged with having endangered it instead,” Judge William B. Traxler Jr. wrote in the majority opinion, which Judge Albert Diaz joined.

Traxler wrote that the only constitutional privilege Risen was entitled to invoke was the Fifth Amendment privilege against self-incrimination, but that he has already been granted immunity for prosecution “for his potential exposure to criminal liability.”

In a dissenting opinion, Judge Roger L. Gregory wrote that a reporter’s ability to protect sources is key to the sort of free press envisioned by the Founding Fathers.

“The majority reads narrowly the law governing the protection of a reporter from revealing his sources, a decision that is, in my view, contrary to the will and wisdom of our Founders,” he wrote.

Neither the Justice Department nor Risen’s lawyer immediately answered requests for comment. The ruling could be appealed to the full appeals court or the U.S. Supreme Court.

Prosecutors allege that Sterling was a key source in Risen’s 2006 book “State of War.” One chapter in the book details the CIA’s botched effort during the Clinton administration to thwart Iran’s nuclear ambitions by secretly feeding the Iranians intentionally flawed blueprints through a Russian intermediary.

Barry Joel Pollack, an attorney for Sterling, said the dispute involves “a fundamental First Amendment issue” and he would be surprised if Risen did not appeal.

“It’s a disappointment for the public’s right to know what its government agencies are doing,” said Lucy Dalglish, the University of Maryland journalism dean and former executive director of the Reporters Committee for Freedom of the Press. She said she was disturbed that the court’s majority “did not recognize the value of a free press at all.”

Risen has refused to speak with government attorneys about his sources, and he didn’t testify before the federal grand jury that indicted Sterling in 2010 on charges of unauthorized retention and communication of national defense information, unauthorized conveyance of government property, mail fraud and obstruction of justice.

“They got an indictment without Jim testifying,” Dalglish said. “If they got an indictment, why do they need his testimony at trial?”

Traxler wrote that while the government could use hearsay testimony and introduce phone records and emails as evidence, those forms of circumstantial evidence are a poor substitute for testimony from a witness believed to have firsthand knowledge of the offenses.