The three-year legal ordeal of New York Times reporter James Risen is not over. But his battle with Justice Department prosecutors to avoid testifying before grand juries investigating allegations that led to the indictment of a former CIA officer was laid out last week publicly for the first time in a once-top secret judicial opinion.

In that November 2010 decision, U.S. District Court Judge Leonie M. Brinkema, who sits in Alexandria, granted Risen’s motion to quash a subpoena from the Obama Justice Department that called for him to testify before the grand jury in the case being put together against Jeffrey A. Sterling, who as a CIA case officer was involved in a highly sensitive attempt to sabotage Iran’s nuclear weapons program during the Bush administration.

Code-named Merlin, the clandestine operation became Chapter 9 in Risen’s book, “State of War,” which was published in January 2006. As Brinkema said in her opinion, the 2010 grand jury had been investigating not who Risen’s source was, but how, when and why the highly classified CIA information “was leaked to journalist James Risen.”

Risen was first subpoenaed in the case in January 2008 to get him to identify his source. That subpoena was partially quashed because the court found “that the government already had strong evidence against Sterling and that Risen’s testimony would simply amount to ‘the icing on the cake,’ ” according to Brinkema.

Under Justice Department rules, and previous court decisions, reporters are not to be called before grand juries if the government had not previously exhausted other means to gather information or if enough evidence for indictment had already been obtained.

Brinkema’s opinion, which reviewed the government’s information about Sterling and Risen, shows why Risen was not needed for the government to find probable cause to indict Sterling as the leaker of the information.

Sterling, according to the opinion, dealt with Risen after the then-CIA officer, an African American with seven years of service, had been questioned about failing to meet performance targets. In August 2000, he filed a discrimination complaint against the agency.

After the suit was dismissed, Brinkema said Sterling’s employment was ended in January 2002. In March 2002, Risen wrote about the discrimination suit in which he described Sterling as having been “assigned to try to recruit Iranians as spies.”

A year later, in March 2003, Sterling met with two staffers of the Senate Select Committee on Intelligence and discussed his lawsuit as well as the clandestine Iranian project. One of staffers later told the government, “Sterling also threatened to go to the press,” though the staffer could not recall whether it was in regard to Merlin or the discrimination case. However, the lawsuit was already public knowledge.

From Feb. 27 to March 29, 2003, the government said there were seven calls placed between Sterling’s home phone and Risen’s home phone. In his own affidavit, Risen said he learned about Merlin in 2003 from sources to whom he promised confidentiality.

Four days after his last phone call with Sterling, Risen called public affairs officers at the CIA and the National Security Council, asking questions about the Iran operation. His call apparently cased a stir within the Bush administration because on April 30, 2003, Risen and the Times’s Washington bureau chief, Jill Abramson, met with national security adviser Condoleezza Rice and CIA Director George Tenet, who tried to convince them not to publish an article about Merlin. Less than a week later, “Abramson told the government that the newspaper had decided not to publish the story,” said the opinion.

Risen did not drop the Merlin story, however. Phone records obtained by the government showed more than 19 phone calls in 2003 and 2004 between the New York Times’s Washington office and a Missouri home where Sterling was living and the office where he worked. An FBI search of a computer to which Sterling had access showed 27 e-mails between Sterling and Risen, including one in May 2004 in which Risen wrote, “I want to call today. I’m trying to write the story.”

In September 2004, Risen sent a book proposal to Simon & Schuster and in November 2005 he provided a near-final version of the manuscript. After the book was published, a grand jury witness testified that she and Sterling saw a copy at a bookstore and Sterling “without looking at the book [said] that Chapter 9 [which described Merlin] was about work he had done at the CIA,” according to Brinkema’s opinion.

While Risen argued in court papers that the subpoenas were partly an attempt to harass him for exposing Merlin and other classified operations, including the post-Sept. 11 wiretapping articles that earned him a second Pulitzer Prize, Brinkema decided the issue on the fact that the government had “more than enough evidence to establish probable cause to indict Sterling.”

Two matters remain.

In the course of his reporting, Risen apparently discussed the CIA Iran operation with another of his confidential sources, a “former government intelligence official.” That person told the grand jury “that Risen told him that Sterling was his source about the [deleted] operation,” according to Brinkema’s opinion. The question of whether Risen had waived the privilege was left hanging when the Bush administration ended in 2009.

In her decision, Brinkema wrote that she accepted Risen’s explanation that his identifying Sterling as his source to the former intelligence official “was also made in confidence as part of his news gathering” and as such apparently did not mean he had waived the journalist privilege. Of course, that did not protect the former intelligence official, who testified about the conversation to the grand jury.

More importantly for Risen, Brinkema also wrote that were Risen subpoenaed for Sterling’s trial, her “analysis might well change” because the government faced a higher burden of proof — Sterling’s guilt beyond reasonable doubt.

Risen has now been subpoenaed for Sterling’s trial. He has offered to appear, but solely to authenticate the facts in his book and articles. To do that he wants a protective order to ensure questions do not go beyond that area, according to a motion filed June 21 .