An Army veteran set a fire, ignited fireworks and waved an air rifle at passers-by outside a building in Lower Manhattan in an attack targeting federal immigration authorities, law enforcement officials said.

The veteran, Andrew Arrabaca, 43, of Poughkeepsie, N.Y., was taken into custody in the attack shortly after 8:30 a.m. outside 26 Federal Plaza by federal protective officers and a security guard at the scene, according to the Federal Bureau of Investigation. The building houses dozens of federal agencies, including U.S. Immigration and Customs Enforcement, and it has long been the target of threats.

James Barnacle, the assistant director in charge of the F.B.I.’s office in New York, said an immigrant who had shown up for a status hearing suffered minor injuries during the episode, as did two officers who subdued Mr. Arrabaca.

Mr. Arrabaca has not yet been charged. Although officials have not established a motive for the attack, Mr. Barnacle said that Mr. Arrabaca, who served in the Army from 2001 to 2005 as a missile systems mechanic, made derogatory statements about ICE in an interview with investigators and said he planned to harm more people. Mr. Barnacle said Mr. Arrabaca had two prior encounters with law enforcement, though he declined to provide details.

The authorities recovered two axes, a hammer, a machete and three knives from a cart that Mr. Arrabaca brought with him, Mr. Barnacle said. Officials earlier said they had also recovered a manifesto, two air rifles and what appeared to be gasoline from the cart, which had an “ICE OFF OUR STREETS” poster affixed to it.

“Mr. Arrabaca came armed with bad intentions,” Mr. Barnacle said.

“He did say he was targeting the building and he was OK if he hurt people going in and out of the building, whether they were federal employees or civilians,” he later added.

The building, which houses federal immigration courts and the local ICE field office, has become a flashpoint since President Trump returned to power last year. As Mr. Trump dedicated more resources to immigration enforcement across the country, protests at ICE facilities across the nation surged.

Protesters and elected Democratic officials have focused their efforts in New York City on the building in Lower Manhattan. Some were arrested in September while seeking access to cells inside the building where ICE holds asylum seekers and immigrants. The police had briefly evacuated the building a month earlier after officials discovered envelopes containing white powder.

As a result of the attack, a naturalization ceremony scheduled for Monday was canceled and several agencies in the building closed early, Mr. Barnacle said.

The civilian victim who was hurt during the incident was grazed by fireworks, and an officer was hurt wrestling the suspect to the ground, according to the Department of Homeland Security, the parent agency of ICE. It is unclear how the second officer was injured. The Fire Department said it took the civilian to NewYork-Presbyterian Lower Manhattan Hospital. The officers refused medical attention, officials said.

Jessica Tisch, the New York City police commissioner, said the first 911 call came at about 8:30 a.m. reporting an active shooter at the building. Two more calls quickly followed, reporting an explosion and a man setting off fireworks. Police officers from the Fifth Precinct arrived two minutes later, but the suspect had already been detained, she said.

The entire incident was captured by a police surveillance camera posted nearby, she said. Mr. Arrabaca first ignited a bundle of fireworks that began to smoke near the employee entrance on Worth Street. Then he took out a rifle and fired several pellets, she said. Next, he poured a bucket full of flammable liquid out at the entrance and set it on fire, she said.

The authorities found a Toyota RAV4 belonging to Mr. Arrabaca in Harlem and are seeking a warrant to search it, she said. The car was parked near the intersection of West 124th Street and Broadway, not far from a community health center whose address Mr. Arrabaca listed on his voter registration.

The episode rattled residents of apartment buildings on the other side of Worth Street, several of whom recorded video of the attack. One woman said she ran over to her window after hearing the pop of the fireworks. She said she saw a man pick up a gun, and she started recording a video.

In the video, which she shared with The New York Times, a man wearing baggy pants, a graphic T-shirt and a helmet can be seen picking up an orange bucket of liquid out of a cart and pulling a lighter out of his pocket. Then, he hustles toward the entrance, where he pours the liquid on steps between two planters and sets fire to it.

As bright orange flames and dark smoke shoot up, he runs back to his cart and picks up a rectangular object. Then he runs back toward the fire, stopping several feet away and gesturing as if he was beckoning a confrontation. Then, he tosses the item into the fire.

He runs back toward the cart once again, where an officer confronts him as another officer with a dog runs off with a brown rifle from the cart, according to the video. The suspect falls to the ground with the first officer, as backup arrives and helps pin him to the ground.

In a statement, Mayor Zohran Mamdani called the incident “deeply disturbing.”

“I’m relieved no one was seriously injured and that a suspect is in custody,” he said, adding that his team was monitoring and supporting the federal investigation. “Our administration will continue to ensure that every New Yorker is safe in their city — and hold accountable any who threaten that.”

According to the authorities, Mr. Arrabaca had taken the subway from Harlem to Penn Station late Sunday and spent the night sleeping on the street near the Holland Tunnel. Around 5 a.m., he wandered over to the area near the building.

Mr. Arrabaca could not be reached for comment because he remained in custody. It was unclear whether he had a lawyer.

At the home of his father, Perfecto Arrabaca, in a leafy street in Forest Hills, Queens, a man who came from the backyard to the front door identified himself as F.B.I. agent, but declined to answer any questions.

Near Federal Plaza early Monday, residents, workers and court visitors were alarmed by the sound of the fireworks.

Christopher Delaroa ran to his seventh-story apartment window on Worth Street across from the federal building when he heard his husband shout in alarm.

Outside, he saw a man shooting pellets near the building’s employee entrance. Workers arriving for the day dashed into the building and ran down the street in terror.

John Jang was opening his shop, KC Novelty, near the southwest corner of Worth and Broadway when he heard the “Ta-ta-ta-ta-ta” of fireworks and then saw the fire and smoke. He said he saw several people who had been waiting in line to get into the public entrance at the front of the building run or walk away.

“Everyone was confused,” he said. “People were running, people were clearing.”

Emma Goldberg, William K. Rashbaum and Hurubie Meko contributed reporting. Alain Delaquérière contributed research.