[What you need to know to start the day: Get New York Today in your inbox.]

Around the anniversary of the Sept. 11 attacks last year, Ashiqul Alam voiced his admiration for their mastermind, Osama bin Laden, and said he wanted to carry on Bin Laden’s legacy of violent extremism, court documents said.

“He did what he is supposed to do,” Mr. Alam, 22, said, according to a criminal complaint. “Now it’s up to us.”

That sentiment, expressed to an undercover law enforcement agent, kicked off a series of conversations about a potential terrorist attack in New York City that ultimately led to Mr. Alam’s arrest on Thursday, the authorities said.

Mr. Alam, a green-card holder from Bangladesh who lives in Queens, was taken into custody after trying to buy two Glock pistols with defaced serial numbers from an undercover officer, officials said.