One of the alleged homegrown terrorists also expressed interest in bombing the Empire State Building, police Commissioner Raymond Kelly said.
But there was no indication that the plot orchestrated as part of a sting operation ever put New Yorkers in danger and no evidence that the men were affiliated with any terrorist organization.
Ahmed Ferhani, a 26-year-old of Algerian descent, and Mohamed Mamdouh, a 20-year-old of Moroccan descent, plotted to bomb a "major synagogue" in Manhattan and bought several weapons and an inert hand grenade from an undercover officer, city officials said in announcing the arrests.
Ferhani and Mamdouh were arraigned in Manhattan court late Thursday afternoon. Ferhani wore a pin-striped suit and carried a Yankees cap, Mamdouh was wearing jeans. They were being held without bail and face life in prison if convicted.
Their attorneys said the two denied the charges.
"Mr. Ferhani tells me he hasn't committed any crime at all," said lawyer Stephen Pokart.
Mamdouh's attorney, Steven Fusfeld, noted that even under the prosecutor's version of the events, which he doesn't think was true, Mamdouh's alleged involvement is less than Ferhani's and it wasn't right to treat them both the same.
"My client says he is not guilty of these crimes," he said. "He's upset because he maintains he committed no crime."
Officials said investigators had been using an undercover detective wearing a wire to track Ferhani for several months. They said the detective heard Ferhani say he hated Jews and was fed up with the way Muslims - especially Palestinians - were treated around the world.
"They're treating us like dogs," Ferhani said once, according to Kelly.
Ferhani is also the one who expressed interest in the Empire State Building attack, Kelly said.
According to a criminal complaint drafted under state terror laws, Ferhani told the detective about "his intent to participate in jihad," meaning holy war, and that "he would become a martyr."
Over time, Ferhani "showed a pattern of growing anger, Manhattan District Attorney Cyrus Vance said.
"His plans became bigger and more violent with every passing week," Vance said.
The undercover detective had several meetings with the men during which Ferhani discussed the idea of attacking a synagogue, the complaint said. Mamdouh emphasized the need for proper training, the complaint said, so they would not get caught like "the one that put the car in Times Square" - a reference to the failed bombing last year by Faisal Shahzad.
Ferhani suggested disguising himself as a worshipping Jew so he could infiltrate a synagogue and leave a bomb inside, the complaint said. He also discussed using grenades, "and described pulling the pins and throwing them into the synagogue," it added.
On May 5, the undercover detective introduced the men to another officer pretending to be an illegal gun dealer at a meeting where Ferhani stated he needed the weapons "for the cause," the complaint said.
"We gonna be victorious," it quoted Ferhani as saying.
At a roadside meeting Wednesday on Manhattan's West Side, one of the undercover officers handed Ferhani a bag holding three handguns, three boxes of ammo and the inert grenade. As soon as Ferhani put the bag into the trunk of a car, he was arrested, the complaint said. Mamdouh was picked up nearby.
New York City police have been on high alert for potential threats to the city since the U.S. raid that killed al-Qaida leader Osama bin Laden over a week ago, though Kelly said the men had no apparent link to al-Qaida.
"We are concerned about lone wolves acting against New York city in the wake of the killing of bin Laden," Bloomberg said. "Those perhaps are the toughest to stop."
Officials refused to give details on how the first undercover officer met Ferhani, who later introduced the officer to Mamdouh.
Ferhani, who had been arrested for a robbery in Manhattan last October, was known to the department through intelligence before the arrest. Police said they shared the information with the Joint Terrorism Task Force, which declined to pursue the case federally.
New York passed its own anti-terrorism law within six days of the Sept. 11, 2001, attacks, but this case is the first time it has been used to prosecute suspected terrorism.
"New York City is an international symbol of freedom and liberty, and for that reason we will always be a target," Bloomberg said. "And we will always be on guard to protect the people of this city."
Authorities said Ferhani, who is unemployed, moved to the U.S. in August 1995 from Algeria with two siblings and his parents, who claimed asylum. He has been living in Queens and had been granted permanent resident status by authorities, but he is facing deportation.
Mamdouh, a tall lanky man who is a native of Casablanca, is a taxi service dispatcher. He came to the United States with his parents in August 1999 and is now a U.S. citizen, officials said. His attorney said he lives in Queens with his brother and sister, and his parents are local business owners.
The case recalled another NYPD investigation that resulted in the conviction of a Pakistani immigrant on charges he plotted to bomb the subway station in Herald Square to avenge the wartime abuses of Iraqis.
The suspect, Shahawar Matin Siraj, had caught the attention of a police informant and an undercover officer - both assigned to track Islamic extremists following the Sept. 11 attacks - with his anti-American rants.
After plotting with the informant, Siraj and another man who later became a cooperator against him were arrested on the eve of the 2004 Republican National Convention carrying crude diagrams of the subway station situated below a dense shopping district that includes Macy's flagship department store.
Siraj was sentenced in 2007 to 30 years in prison.
Associated Press writers Jim Fitzgerald, Chris Hawley and Tom Hays contributed to this report.