The feds say its surveillance program foiled a plot to attack the New York Stock Exchange (pictured). Photo: Getty Images

GUILTY: Khalid Ouazzani (left) who reportedly had a role in the plot to blow up the exchange, implicated Wesam El-Hanafi and Sabirhan Hasanoff. (Getty)

Secret US surveillance foiled an al Qaeda plot to blow up the New York Stock Exchange, the FBI revealed to Congress yesterday.

A Brooklyn accountant “cased” the stock exchange in 2008 under orders from a mysterious al Qaeda leader in Yemen known as “the Doctor,” according to federal authorities.

But the accountant and two other suspected terrorists were arrested before the plot went beyond what the FBI called “very initial stages.”

The scheme came to light yesterday as government officials said the classified phone/Internet monitoring program had foiled more than 50 terror attacks in 20 countries.

The officials gave few new details — but revealed the existence of the Wall Street plot.

It was detected after US authorities traced communications between an al Qaeda member in Yemen and a Kansas City auto-parts dealer, Khalid Ouazzani, FBI deputy director Sean Joyce told the House Intelligence Committee.

Investigators put Ouazzani, 35, under court-ordered electronic surveillance. He was arrested in February 2010 and pleaded guilty three months later to funneling $23,000 to al Qaeda.

But as part of his bargain, Ouazzani, a former New Yorker, became a cooperating witness against two Brooklynites, Sabirhan Hasanoff, 37, and Wesam El-Hanafi, 38, authorities said.

Hasanoff and El-Hanafi were later arrested in the United Arab Emirates and brought to New York to face charges of planning an undisclosed act of “terrorism against the United States.”

They pleaded guilty last June to a lesser charge of financially supporting al Qaeda. There was no mention of the stock exchange in any of the three guilty pleas.

But in a sentencing memorandum filed May 31 in Manhattan federal court, prosecutors said Hasanoff — “at the direction of a senior terrorist leader” — “cased” the New York Stock Exchange in 2008.

This was “unquestionably with the purpose of gathering information for a future terrorist attack,” the memo said.

It added that Hasanoff, who “worked for years at a succession of blue-chip accounting firms,” had gone to Yemen in 2008 where he was given orders from two men he knew only as al Qaeda leaders identified as “the Doctor” and “Suffian.”

Hasanoff sent a one-page report on his casing of the stock exchange to “the Doctor,” who was later arrested and interviewed by the feds.

The sentencing memo said Hasanoff also supplied terrorists with “a remote-controlled device to be used for detonating explosives.”

Senior congressional leaders who regularly get briefed on intelligence matters said they learned of the Wall Street plot only yesterday.

But Sen. Jay Rockefeller (D-W.Va.), said he wasn’t surprised the stock exchange was on a terror hit list, “because it’s on everybody’s list.”