Updated

NEW YORK -- Two U.S. residents, including one who complained that the world was treating Muslims "like dogs," bought guns and a grenade and wanted to carry out a terror plot against a New York synagogue, officials said Thursday.

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, said that even under the prosecutors' version of the events, which he didn't say was true, Mamdouh's alleged involvement is less than Ferhani's and it wasn't right to treat them equally.

"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 and the men had several meetings 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 was so aware of the possibility of getting caught he suggested renting a farmhouse upstate where they could shoot weapons to train and speak freely, police said.

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.

"It was clear that they intended to do that bombing on behalf of Islam and to send a message to the Jewish population," Assistant District Attorney Margaret Gandy told a judge.

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, who had been dropped off nearby, was arrested soon afterward.

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 at a Midtown hotel, 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 the statute has been rarely used.

"New York City is an international symbol of freedom and liberty, and for that reason we will always be a target," Mayor Michael Bloomberg said. "And we will always be on guard to protect the people of this city."

Authorities said Ferhani is an unemployed aspiring actor who may have worked at swank department stores. They say he 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, but is facing deportation because of some brushes with the law, Gandy said. Details weren't immediately available.

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 attended a local high school and lives in Queens with his brother and sister, and his parents are local business owners.

He is also facing an unrelated burglary case in Queens, Gandy said.

Extra security had already been in place at local religious institutions since the death of bin Laden. David Pollock, who helps advise synagogues on security and emergency preparedness for the Jewish Community Relations Council of New York Inc., said there has long been a heightened awareness among local Jewish organizations that they could be targeted in terror attacks, citing the 2009 arrest of four people who plotted to bomb Bronx synagogues.

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 Cristian Salazar, Jim Fitzgerald, Chris Hawley and Tom Hays contributed to this report.