Crowds enjoy a sunny day in New Yorks Times Square, August 21, 2018. (Photo by Daniel SLIM / AFP)        (Photo credit should read DANIEL SLIM/AFP/Getty Images)
DANIEL SLIM/AFP/Getty Images
Crowds enjoy a sunny day in New Yorks Times Square, August 21, 2018. (Photo by Daniel SLIM / AFP) (Photo credit should read DANIEL SLIM/AFP/Getty Images)
Now playing
01:43
Police: Man plotted to denotate explosives in Times Square
Now playing
05:18
Coinbase CFO: We're an on-ramp to the crypto economy
Now playing
05:18
Anderson Cooper explains how he overcomes being shy
CNN
Now playing
02:12
'Too dangerous to do anymore': Sacha Baron Cohen on Borat
Christopher Hamilton
Now playing
01:01
Volcanologist shares what he prefers to cook on lava flows
John Avlon 0413 Wallace
CNN
John Avlon 0413 Wallace
Now playing
03:31
Avlon compares Tucker Carlson's comments to George Wallace
Kristina Barboza
Now playing
03:09
Grieving mom's advice to other families: You can try to help, support and love
screengrab hong kong oscars
IMDB / Field of Vision
screengrab hong kong oscars
Now playing
02:50
Hong Kong won't air Oscars for the first time since 1968
Now playing
01:27
See the first community of 3D-printed homes
Burlington, MA Headquarters
Nuance
Burlington, MA Headquarters
Now playing
01:34
Microsoft to buy AI company Nuance
Now playing
02:50
Sleep doctor tells Anderson Cooper how long a power nap should be
WASHINGTON, DC - DECEMBER 01: Chairman of the Federal Reserve Jerome Powell testifies during a Senate Banking Committee hearing about the quarterly CARES Act report on Capitol Hill December 1, 2020 in Washington, DC.  Treasury Secretary Steven Mnuchin also testified at the hearing. (Photo by Susan Walsh-Pool/Getty Images)
Susan Walsh/Pool/Getty Images
WASHINGTON, DC - DECEMBER 01: Chairman of the Federal Reserve Jerome Powell testifies during a Senate Banking Committee hearing about the quarterly CARES Act report on Capitol Hill December 1, 2020 in Washington, DC. Treasury Secretary Steven Mnuchin also testified at the hearing. (Photo by Susan Walsh-Pool/Getty Images)
Now playing
02:06
Fed chief: The economy is about to grow more quickly
"Saturday Night Live" / NBC
Now playing
01:47
'SNL' sees Minnesota news anchors take on the Derek Chauvin trial
Now playing
02:23
Pubs in England reopen after months of lockdown
DORAL, FLORIDA - AUGUST 27:  A Trump National Doral sign is seen at the golf resort owned by U.S. President Donald Trump's company on August 27, 2019 in Doral, Florida. President Trump said the United States may host the next G7 gathering at the golf resort. (Photo by Joe Raedle/Getty Images)
Joe Raedle/Getty Images
DORAL, FLORIDA - AUGUST 27: A Trump National Doral sign is seen at the golf resort owned by U.S. President Donald Trump's company on August 27, 2019 in Doral, Florida. President Trump said the United States may host the next G7 gathering at the golf resort. (Photo by Joe Raedle/Getty Images)
Now playing
03:46
'That is obviously false': CNN reporter on Trump supporter's attempt to rewrite history
Now playing
03:35
Why CrossFit CEO wants gyms included in infrastructure bill
(CNN) —  

A man who investigators allege was plotting to kill people in New York’s Times Square is being held on weapons charges, accused of buying two illegal pistols from an undercover government agent, federal prosecutors said Friday.

Ashiqul Alam, 22, of Queens, was charged in a federal court in Brooklyn with knowingly receiving two firearms with obliterated serial numbers, a criminal complaint reads. He is being held without bail.

Alam briefly appeared in Brooklyn federak court Friday for his arraignment, wearing a purple T-shirt, jeans and red and black sneakers. His attorney proposed a bail package that included a $200,000 secured bond to be signed by Alam’s parents, who were also in the courtroom. A federal prosecutor argued that there was no condition that would be appropriate, saying “the nature and circumstances of this offense are extremely serious.”

A magistrate judge denied bail, noting that Alam poses a danger to the community and is a flight risk.

Alam, a Bangladeshi citizen and lawful permanent US resident, was taken into custody Thursday after giving an undercover agent a total of $800 for two pistols that had the manufacturers’ serial number scratched off, the complaint alleges.

Authorities allege Alam, in meetings with an undercover agent beginning in August, repeatedly expressed a desire to buy weapons, explosives and a suicide vest for terror attacks at either a large event at Times Square or in Washington in order to kill what the complaint describes only as a senior government official.

The complaint alleges Alam focused on Times Square as time went on, and undercover investigators eventually set up Thursday’s gun purchase in Brooklyn, the complaint reads.

“As alleged, Ashiqul Alam bought illegal weapons as part of his plan to kill law enforcement officers and civilians in a terrorist attack on Times Square,” Richard Donoghue, US attorney for New York’s Eastern District, said in a news release.

“What he did not know was that he was buying weapons from government agents, who were monitoring his plans and intervening to prevent those plans from escalating into deadly violence,” Donoghue said.

Alam also had expressed interest in purchasing explosives with the intention of detonating them in Times Square, a law enforcement source told CNN on condition of anonymity.

The Federal Bureau of Investigation’s Joint Terrorism Task Force along with the New York Police Department handled the operation to investigate and arrest the man, the law enforcement source told CNN.

William F. Sweeney Jr., assistant director in charge of the FBI’s New York field office, said in Friday’s news release that Alam is accused of “purchasing weapons to kill New Yorkers, target an elected official and attack police officers.”

Sweeney did not name the elected official or say whether the official is separate from the one mentioned in the complaint.

“There is more to this case than just talk and the desire to carry out a terrorist attack,” Sweeney said. “Individuals who believe in the distorted and deadly propaganda of terrorist organizations and work toward acting on those deadly impulses are incredibly dangerous and unpredictable.”

He met with an undercover agent for months

Alam met with an undercover agent for several months. He spoke approvingly about various terrorist attacks – including the September 11 attacks – and terror groups such as ISIS, surveyed Times Square while “looking for potential targets,” and discussed the purchase of firearms, according to the complaint.

Details about how Alam initially met the undercover agents weren’t immediately available. He had been under surveillance for some time, a law enforcement source told CNN on Friday.

In a meeting with an agent last September 11, Alam praised Osama bin Laden and said bin Laden’s “mission is a complete success, thousands of American soldiers died and trillions of their monies gone in the war,” according to the complaint.

In January, Alam traveled with the agent to shooting range in Pennsylvania, where they took a lesson. During the drive, the complaint said, Alam discussed ISIS and said,” I want to die fighting man.”

Months later, they returned to the shooting range and the agent asked Alam whether he would use a firearm during the attack. He told the agent he “would potentially use a firearm after first using a bomb,” the complaint said.

They began discussing the purchase of two pistols in March and Alam asked the agent to help him contact someone who could sell them to him. Alam was arrested after he bought the firearms from another undercover agent Thursday, officials said.

Alam is scheduled to appear again in a Brooklyn federal courtroom June 21.

Times Square, the commercial and entertainment hub around Broadway and 7th Avenue in Midtown Manhattan, draws about 380,000 pedestrians a day, according to the Times Square District Management Association, making it one of the most visited locations in the world.

The area has been the subject of terror plots before. In 2010, Pakistani-American Faisal Shahzad tried, and failed, to set off a bomb in a vehicle in Times Square, authorities said. He was arrested after street vendors tipped off police to the abandoned car.

He pleaded guilty that year to charges including attempting to use a weapon of mass destruction and was sentenced to life in prison.

CNN’s Nicole Chavez, Madeline Holcombe, Joe Sutton contributed to this report.