The man, identified as Ashiqul Alam, was intercepted by federal and local officials, and he posed no imminent threat.
He was arrested on charges of attempting to buy a gun with a defaced serial number, the sources told ABC News. He is expected to appear in federal court in Brooklyn on Friday afternoon.
Alam, who lives in the Jackson Heights neighborhood of Queens, was detected both inquiring about obtaining grenades and discussing using them in Times Square, the sources told ABC News.
He is not believed to be linked to any other people or part of a larger plot.
The U.S. Attorney’s Office is expected to comment later Friday.
The NYPD referred all questions to the FBI.
Alam is represented by Federal Defenders, who offered a bail package of $200,000 and to have their client wear an ankle monitoring device and home confinement.
But a federal court judge, Magistrate Cheryl Pollak, ordered Alam to be "permanently detained," labeling him a "danger" to the community based on his statements in the complaint and his desire to purchase firearms with the serial numbers scratched out.
He is scheduled to appear in court on June 21.
Times Square has been the site of a few attempted attacks in recent years. In May 2017, a man crashed his car into a group of people, killing one and injuring 20 others. The suspect, Richard Rojas, was later determined to be on drugs and suffering from mental illness.
The most noteworthy example of a foiled terror attack in Times Square came in 2010 when two good Samaritans noticed a smoking car and alerted authorities, who foiled the car bomb attempt.
ABC News Christina Carrega contributed to this report.