WASHINGTON – FBI Director Robert Mueller is leaving the law enforcement agency that he has run every day since the week before the Sept. 11, 2001, terrorist attacks in the same way that he entered it: being grilled about how the FBI is carrying out the most high-profile criminal investigations in the country.

For Mueller, Thursday marked another routine appearance on Capitol Hill. There were questions about leak probes involving the Associated Press and Fox News; the Boston Marathon bombings; the attack at Benghazi, Libya, that killed four Americans; and two government surveillance programs so breathtaking in scope that they instantly became a major Washington controversy when their details spilled out into the public record last week.

It was Mueller’s last appearance before the House Judiciary Committee. His last day on the job is Sept. 4.

He graciously accepted the occasional gestures of thanks from committee members for his public service. He gave as good as he got when the back-and-forth got testy.

For years, the National Security Agency has been collecting millions of U.S. phone records along with digital communications stored by nine major Internet companies.

In his three hours of testimony, Mueller defended the two government surveillance programs and deplored the leaks that brought them to light.

“Every time that we have a leak like this — and if you follow it up and you look at the intelligence afterwards” — the terrorists “are looking at the ways around it,” Mueller said.

The admitted leaker of the National Surveillance Agency’s secrets, 29-year-old NSA contractor Edward Snowden, is the subject of an ongoing criminal investigation, Mueller testified.

In the leak probe involving the AP, the government seized the records for more than 20 separate telephone lines assigned to the AP and its journalists in April and May 2012.

“I will tell you that I do believe that there was a substantial effort made to minimize the request” for the phone records, Mueller said of that episode, which had involved an AP story about a CIA operation targeting terrorists in Yemen.

In the leak probe involving Fox News, an affidavit seeking a search warrant in the investigation characterized Fox journalist James Rosen as a probable co-conspirator to the alleged leaker, a State Department contractor.

Mueller said that “quite often in search warrants there are occasions where a person will be mentioned as having culpability, but there will be no discussion or anticipation of prosecution.”

“I did briefly review the affidavit when the issue arose. So I am somewhat familiar with it,” Mueller said. “I can tell you that the focus of our investigations are on the person within the government who has leaked the information.”