The feds got their man recently, but they broke a lot of rules doing so. That shouldn’t be allowed to happen again.

In announcing that former FBI agent Donald J. Sachtleben was the illegal source of an Associated Press story on a foiled aircraft bombing plot in Yemen, the Justice Department said he was identified by subpoenaing the telephone records of an AP reporter.

But the Justice Department didn’t just collect the telephone records of a single reporter. It seized all telephone records for a period of two months for The Associated Press in Washington, D.C., New York City, and Hartford, Conn., and the home phones of reporters, a total of some 20 telephone lines, gathering vast data on AP operations in a wholly unprecedented sweep. It didn’t inform the AP before or after doing so.

That violated its own rules, spelled out in the Code of Federal Regulations and the procedural manual for U.S. Attorneys. The rules say the Justice Department must avoid actions against news organizations except in very serious cases because the First Amendment guarantees freedom of the press. They say that except in very special circumstances Justice must notify news organizations and reporters that it wants their phone records, giving them the option of going to court to block the request. In this case it did not.

The rules say that the Attorney General himself has to agree before a subpoena can be issued for reporters and news organizations or their phone records. In this case, he didn’t.

Defending the subpoenas, Attorney General Eric Holder said last May they were justified by a serious national security leak. But the AP tells a different story.

In its May 7, 2012, story on the foiled plot the AP said it had agreed with the White House and CIA not to publish its information while the “sensitive intelligence operation was … under way.” The AP waited, but decided not to hold off any longer when it learned that the White House planned an official announcement the next day.

If the White House planned to announce the success of the operation, it is hard to see how the AP story could have been damaging to national security.

In a related case, the Justice Department in 2010 charged a government consultant with giving Fox News reporter James Rosen secret information on intelligence sources in North Korea. To obtain a warrant for Mr. Rosen’s personal emails, the government described him as a “co-conspirator” in a criminal act. Critics have rightly decried the “chilling” effect of the Rosen case on reporters’ access to sources.

In the AP case, media organizations protested what the news agency described as the “overbroad” seizure of private information on its operations that “the government has no conceivable right to know.” President Obama subsequently asked Justice to review its rules on surveilling journalistic operations. After meetings with media representatives, Mr. Holder issued cosmetic revisions to the effect that the rules really mean what they say, and together with the White House proposed that Congress pass a media shield law.

But a shield law has troubling aspects of its own, since it allows the government to define “the press.” The First Amendment already prohibits laws “abridging the freedom … of the press.”

But there is a very real need to hold officials like Mr. Holder (and the White House itself) accountable for willfully trampling media rights, a tendency all too typical of this administration.