With the new agreement, however, the White House has now moderated that position.

“We expect this proposal to move forward with bipartisan support, and the president looks forward to signing it into law,” said Ben LaBolt, a White House spokesman, who noted that the Obama administration was “the first administration in history to support media shield legislation.”

The protection would apply not only against subpoenas for reporters’ testimony or information but also against investigative efforts to obtain phone and Internet records to find out who had been talking with them.

Under the agreement, the scope of protection for reporters seeking to shield the identities of confidential sources would vary according to the nature of the case: civil, criminal or national security.

In civil cases, the litigants seeking to force reporters to testify would first have to exhaust all other means of obtaining the information. Even then, the judge would apply a “balancing test,” and the burden would be on the information seekers to show by a “preponderance of the evidence” why their need for the testimony outweighed the public’s interest in news gathering.

Ordinary criminal cases, as in prosecutors’ effort to find out who leaked grand jury information about professional athletes’ steroid use to The San Francisco Chronicle, would work the same way, except that the balancing test would be heavily tilted in favor of prosecutors. For a judge to quash a subpoena, the burden would be on a reporter to make it “clear and convincing” that the public interest in the free flow of information should prevail.