On Tuesday, District Attorney Cyrus Vance Jr. called the case "groundbreaking," adding that the plea showed that "the threat of terrorism from these lone wolf radicals is real."
Ferhani and Mamdouh were arrested after Ferhani bought three handguns, ammunition and an inert grenade from an undercover detective, police said.
Mamdouh, a 21-year-old American citizen of Moroccan descent, had been dropped off nearby before the buy and was arrested soon afterward, according to police. He has pleaded not guilty.
A grand jury declined to indict the two men on the initial top charge against them, a high-level terror conspiracy count. But they were indicted on other terror and hate crime charges.
The judge said Tuesday that he had "no problem" with the investigation.
"It stopped what could have been a dangerous situation," he said.
Sentencing was scheduled for Jan. 30.