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, but it was impossible to tell from his generally placid demeanor whether he was pleased or sorry to be leaving. 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.

"One of my problems is that we're going to ... lose our ability to get their communications. We are going to be exceptionally vulnerable," he 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."

The FBI director also got questions about the aftermath of the Boston Marathon bombings when impending court proceedings ended the interrogation of the bombing suspect, Dzhokhar Tsarnaev.

"In a very narrow sliver of cases where it is terrorism, where the threat is substantial, I would say that one could look at opportunities for giving those questioners additional time to extract information that may protect the public," Mueller told the committee.

Mueller also touched on the FBI's delay in getting agents into Benghazi last year to conduct an investigation of the attack that killed four Americans, including U.S. Ambassador Chris Stevens.

The two-week delay "adversely impacted the ability to gather evidence in a variety of ways and adversely impacted the investigation," Mueller said.

"In Benghazi, there is no law enforcement," he explained. "There is nobody that you can deal with in terms of assuring your security." In addition, putting agents into the country was dependent on getting visas from the Libyan government and "the government then and today is still unstable," Mueller said. "It's very difficult to get any decision made."

As to where the Benghazi probe stands now, Mueller said, "We've had some success that I can't get into today" and that the investigation was ongoing.