Secret US surveillance prevented “dozens” of terror attacks in recent years — and might have foiled the 9/11 hijackers if sophisticated phone tracking had been in place in 2001, the head of the National Security Agency testified yesterday.

Gen. Keith Alexander said US intelligence knew of phone calls Khalid al-Mihdhar made allegedly to an al Qaeda safe house before he hijacked the plane that crashed into the Pentagon.

“We had intercepts on Mihdhar,” Alexander told the Senate Appropriations Committee. “But we didn’t know where he was.”

Mihdhar and another hijacker, Nawaf al-Hazmi, had traveled to San Diego for pilot training.

Had the metadata phone-tracking program secretly created after 2005 been in effect in 2001, Mihdhar and Hazmi and the other 9/11 hijack teams might have been located through Mihdhar’s phone, Alexander suggested.

“We could take that number and go backwards in time,” he said, “and if we saw four other groups, we’d say this looks of interest and pass this to the FBI,” he said.

Asked by Sen. Patrick Leahy (D-Vt.) how many attacks have been thwarted by phone tracking and Internet surveillance, Alexander said:

“It’s dozens of terrorist events that these have helped. Both here and abroad, in disrupting, or contributing to the disruption of terrorist attacks.”

He also said leaker Edward Snowden lied when he claimed that by using his NSA access he could “tap into virtually any American’s phone or e-mail.”

“False,” Alexander said. “I know of no way to do that.”

Meanwhile, from the other side of the world, the unrepentant Snowden revealed he’s still in Hong Kong — and dared the Obama administration to extradite him.

“I am not here to hide from justice,” he said — from an undisclosed location. “I am here to reveal criminality.”

“I am neither a traitor nor hero,” he told the South China Morning Post. “I’m an American.”

When Alexander briefed key senators Tuesday, he said he didn’t know where Snowden was, according to Sen. Saxby Chambliss (R-Ga.). But the newspaper located the 29-year-old computer expert.

Snowden claimed he learned yesterday that the United States was trying to “bully” Hong Kong into extraditing him, but he vowed to beat that effort in a local court.

Snowden also made some new claims. He said the United States had hacked into computers all over the world, in 61,000 separate hacking operations.

He said he has documents showing that the United States has been hacking Chinese and Hong Kong computers since 2009, and this revelation might convince Hong Kong to reject an extradition request.

Also yesterday, two FBI agents interviewed the father of Snowden’s girlfriend, Lindsay Mills, at his Laurel, Md., home.

Jonathan Mills said his daughter felt “crushed” after Snowden thrust her into the leak controversy by outing himself.

But now “she’s all right,” “staying with friends” and “thinking about trying to start putting the pieces back together again,” he said.