A federal judge today ordered the jailing of a New York Times reporter for refusing to divulge a confidential source, but a Time magazine reporter facing possible jail time in the same case reversed course and agreed to testify before a grand jury investigating the leak of a CIA agent's identity.

Judith Miller, a national security correspondent for the New York Times, told U.S. District Judge Thomas F. Hogan that she could not break her word in order to stay out of jail. Hogan then ordered her taken into custody immediately for civil contempt of court and incarcerated in the Washington area. She is expected to serve jail time that could last as long as the grand jury continues investigating, possibly until late October.

Miller told the judge that if U.S. troops could risk death in their fight for freedom in Iraq, "surely, I can face prison to defend a free press."

"I have chronicled the dark side of the world, where the law is an arbitrary foil that serves the powerful," she said in court, Washington Post staff writer Carol Leonnig reported. "I also know that the freest and fairest societies are . . . those with a free press . . . publishing information the government does not want to reveal," Miller said.

She said she did not make promises of anonymity lightly, "but when I do I must honor them."

Hogan said he was sending Miller to jail because "there is still a realistic possibility that confinement might cause her to testify."

At the end of the hearing, Miller, 54, was escorted to the basement of the courthouse for processing before being taken, at least temporarily, to the Arlington County Jail in Northern Virginia, Leonnig reported.

"This is a chilling conclusion to an utterly confounding case," New York Times executive editor Bill Keller said outside the courthouse after today's hearing.

Matthew Cooper, 42, a White House correspondent for Time, avoided jail when he told Hogan shortly before his court appearance that his source had specifically released him from any obligation to protect the source's identity.

"I am prepared to testify," said Cooper, who wrote an article about the leak of CIA agent Valerie Plame's identity.

Miller's testimony had also been sought by special prosecutor Patrick J. Fitzgerald even though she never wrote about Plame.

Fitzgerald told the court that Miller must be punished for disobeying the court's order for her to testify, in part because the more than 50,000 newspaper journalists across the country could not be allowed to make their own decisions on whether to obey court orders to disclose sources.

"We are trying to get to the bottom of whether a crime was committed and by whom," Fitzgerald said.

The case has stoked controversy over whether the First Amendment protects reporters who refuse to reveal confidential sources, even in defiance of court orders.

Fitzgerald's grand jury investigation is aimed at determining whether senior Bush administration officials broke the law in July 2003 by knowingly leaking Plame's identity to reporters in retaliation for criticism by her husband. Former ambassador Joseph C. Wilson IV, Plame's husband, had written an opinion piece in which he accused the administration of twisting intelligence about Iraq's purported efforts to acquire nuclear material in Africa. Shortly after the piece appeared in the New York Times, syndicated columnist Robert D. Novak reported that "two senior administration officials" had told him that Plame, whom he identified as "an agency operative on weapons of mass destruction," had suggested sending her husband to investigate a reported Iraqi effort to obtain uranium from Niger.

Under U.S. law, it is a felony to knowingly identify a covert CIA operative.

Novak has refused to comment on whether he has cooperated in Fitzgerald's investigation. But he has deplored the idea of jailing reporters for refusing to reveal sources.

Legal analysts have said Fitzgerald may end up seeking to indict a government official for perjury rather than for the crime he originally set out to investigate: knowingly exposing a covert agent. The prosecutor's court filings also have indicated that he seeks to quash the notion that journalists who protect sources in defiance of court orders deserve any "special treatment." In one of his filings yesterday, Fitzgerald argued that "journalists are not entitled to promise complete confidentiality -- no one in America is."

After today's hearing, Keller, the New York times editor, said the judge's order of jail time for Miller was chilling because it was likely to facilitate "future coverups" involving government information.

"Anybody who believes government . . . should be closely and aggressively watched should feel a chill up their spine today," he said.

Keller denied Fitzgerald's assertion that Miller was attempting to put herself above the law. "The choice she made is a brave and principled choice," he said.

Floyd Abrams, a lawyer representing Miller and a specialist in First Amendment cases, said, "Judy is an honorable woman adhering to the highest tradition of her profession and the highest tradition of humanity."

He said that unlike Cooper, Miller had not received any specific permission from her source to disclose the source's identity. Abrams said a waiver that Fitzgerald said the source signed is not a valid release of Miller's obligation to maintain confidentiality.

"Judy Miller made a commitment to her source, and she's standing by it," Abrams said.

It was not immediately clear whether the same person was a source for both Miller and Cooper. Although Fitzgerald has said the source has waived confidentiality, the prosecutor has not identified the person.

Abrams said Miller was not being sent to the D.C. Jail, a notorious, overcrowded lockup that both she and Cooper had specifically sought to avoid.

Cooper said after the hearing, "This is a sad day, not only for journalists but for our country." He added, "It's a sad time when two journalists who are simply doing their jobs and trying to keep confidences and report important stories face the prospect of going to prison for keeping those confidences."

He said he had told Miller as she left the court "to stay strong." The case, he said, demonstrates the need for some kind of federal shield law to protect reporters from court action for refusing to identify sources.

Cooper said he had expected to be sent to jail as well and had written out a statement last night explaining to the judge that he would "remain in civil contempt" rather than break a two-year-old promise to his source to protect his identity.

The reporter said he told his 6-year-old son this morning that he was going away and was not sure when he would be back.

But then, Cooper said, his source contacted him and dramatically gave him "a specific, personal and unambiguous waiver to speak before the grand jury." Unlike the "government-issued waiver" handed out by the prosecutor, Cooper said, this waiver was "uncoerced."

It was only then, Cooper said, "that I felt free after two years under threat of jail to speak to the grand jury."

In a court filing yesterday, Fitzgerald had urged Hogan, chief judge of the U.S. District Court for the District of Columbia, to order jail time for both Cooper and Miller if they continued refusing to testify before the grand jury.

Fitzgerald argued that Cooper should be compelled to testify even though his editors had already turned over notes and e-mails that identified his sources for an article he wrote about the leak. The prosecutor wrote that "after reviewing the documents provided by Time, Inc., Cooper's testimony remains necessary for the Special Counsel's investigation." He did not elaborate on that point.

Fitzgerald also argued against Cooper's request for home confinement or, failing that, incarceration at a specific federal prison camp -- rather than the D.C. jail -- if the judge ordered him detained for refusing to testify.

Cooper had argued in a July 1 filing that his grand jury testimony "would be duplicative and unnecessary" since Time -- against his wishes -- had already provided the information.

In a separate court filing yesterday, Fitzgerald had reserved his toughest criticism for Miller, whose newspaper has backed her refusal to testify on grounds that she must keep promises not to identify confidential sources in order to preserve access to high-level informants and uphold the public's "right to know."

Miller argued that sending her to jail would not change her refusal to testify, which was "based on journalistic principle grounded on the First Amendment," and would "result only in punishment rather than effective coercion." She also contended that, alternatively, "no more than a very restrictive form of home detention" would be appropriate. If incarceration were "deemed absolutely necessary," her lawyers argued, she should be sent to the federal prison camp for women in Danbury, Conn.

Fitzgerald said Miller's arguments were contradictory and suggested that continuing to defy the court's October 2004 order to testify would go beyond civil contempt and amount to "a crime," possibly exposing her to "subsequent prosecution for criminal contempt."