Investigating the leak of a covert CIA operative's name to the media, Chief US District Judge Thomas Hogan ordered correspondent Judith Miller to jail immediately.
He said she must stay there until she agreed to testify or for the rest of the grand jury's term, which lasts until October.
Another case involving Time magazine reporter Matthew Cooper was resolved when the journalist told the judge he had just received the "express personal consent" of his source to reveal his identity.
"Consequently I am prepared to testify," he said.
Miller told the judge she did not want to go to jail but had no choice but to protect her source.
"If journalists cannot be trusted to keep confidences, then journalists cannot function and there cannot be a free press," she said in a clear, firm voice in the packed courtroom that included her husband and the newspaper's top editor.
The grand jury investigation by special counsel Patrick Fitzgerald, a Justice Department prosecutor, seeks to determine who in the Bush administration leaked the name of covert CIA operative Valerie Plame in 2003 to the media and whether any laws were violated.
Cooper's source gave permission
to reveal names but not Miller's
Plame's name was leaked, her diplomat husband said, because of his criticism of the Bush administration's handling of the Iraq war.
When Hogan ordered Miller to jail, she showed no emotion, and one of her lawyers put his arm around her shoulder. The judge said confinement at a jail in the Washington DC area might convince her to change her mind and testify.
The case has pitted the news media's traditional use of anonymous sources against the efforts by a federal government prosecutor to investigate a possible crime.
Defence Attorney Robert Bennett told the judge that Miller had not committed any crimes and that she never even wrote an article about the Plame matter.
"After 40 years in this business, I have the nagging feeling that Judy Miller may be the only person to go to jail in this case," Bennett said. No one has been charged as part of the grand jury investigation which began in January 2004.
But prosecution lawyers said that Miller has no choice but to cooperate under the law. They said she was defying the law by not testifying and "may be obstructing justice."
In a statement afterward, Arthur Sulzberger, chairman of The New York Times Company and publisher of The New York Times, said: "There are times when the greater good of our democracy demands an act of conscience. Judy has chosen such an act in honouring her promise of confidentiality."