Manhattan’s district attorney said the men had intended to attack a synagogue.
Two men arrested just before midnight on Friday at New York’s Penn Station, in what authorities said was a “developing threat to the Jewish community,” have been charged with multiple felony counts, including criminal possession of a weapon and making a terroristic threat.
Authorities seized an 8-inch military style knife and an illegally held gun with a 30-round magazine from Christopher Brown, 21, and Matthew Mahrer, 22. They also found Mr. Brown in possession of a Swastika arm patch and ski mask.
Law enforcement officials with knowledge of the situation said that threats of violence to Jewish sites, including “shooting up a synagogue,” were recently made in social media posts and that there was a reference to a violent act occurring on Friday.
“A potential tragedy was averted when they were intercepted by police officers at Penn Station,” said Alvin Bragg, the Manhattan district attorney, “given that online postings indicated an intent to use these weapons at a Manhattan synagogue.”
Police said that Mr. Brown had a history of mental illness and had recently expressed an interest in coming to New York to buy a gun.
The police also seized a Glock-style pistol, a large-capacity magazine and 17 9-mm bullets in a bag at an apartment building on the Upper West Side at around 11 p.m. on Friday. The two men were observed on video walking into the building about 45 minutes before, according to the police, and Mr. Mahrer appeared to be carrying the bag.
A posting on a Twitter account that Mr. Brown identified as his indicated on Nov. 12: “Big moves being made on Friday.” And on Thursday, Nov. 17, the same account posted: “Gonna ask a Priest if I should become a husband or shoot up a synagogue and die.” By Friday, Nov. 18, Mr. Brown posted: “This time I’m really gonna do it.”
After the men were arrested, Keechant L. Sewell, the police commissioner, said in a statement that the New York Police Department was “strategically deploying” resources to “sensitive locations” throughout the city based on a threat.
She said that “sharp-eyed” Metropolitan Transportation Authority officers arrested the two while they were entering Penn Station.
On Saturday, Mr. Brown told the police that he and Mr. Mahrer had first gone to St. Patrick’s Cathedral to “get the blessings” before being driven to Pennsylvania by a friend of Mr. Mahrer to buy a gun.
“I cash app paid Matt $650 for the gun,” Mr. Brown told officers. “However I changed my mind because I was nervous about the police and didn’t want the gun anymore, but Matt bought it anyway.”
At that point, the men drove back to Manhattan, he said.
Mr. Brown also told authorities that he operated a white supremacist Twitter group and that Mr. Mahrer was one of his followers.
Gov. Kathy Hochul said in a tweet on Sunday that, in response to recent threats to Jewish and L.G.B.T.Q. communities, she has directed New York State Police to ramp up monitoring and increase support for communities that are potential targets of hate crimes.
Both men were arraigned on Sunday, and Mr. Mahrer was being detained at Eric M. Taylor Center, on Rikers Island. Details on where Mr. Brown was being held weren’t available on the city’s Department of Correction website as of Sunday afternoon.