TRENTON — Krystal Knapp was 15 minutes from the end of her shift as a volunteer at the entrance to the Art All Night festival in Trenton when she heard some scuffling.
Peering into the long and narrow former factory building where the festival was being held, she saw paintings being knocked to the floor. She heard screams and gunshots as people hurtled toward the exit and she was pushed to the ground and trampled.
Ms. Knapp sought shelter behind a car. Then, 15 feet away, one of the gunmen was shot and killed.
The authorities said the shooting appeared to be gang-related and that 22 people were injured; 17 were shot and the others hurt by being trampled. It happened just before 3 a.m. Sunday at a 24-hour art festival cherished by Trenton residents as a testament to the New Jersey capital’s artistic revitalization.
Tensions were rising shortly before the event descended into violent chaos.
“There was a report that the mood inside the venue had been changing,” Angelo J. Onofri, the Mercer County prosecutor, said at a news conference on Sunday.
He said before the shooting there were “numerous physical altercations that took place both inside and outside of the venue.”
The police told organizers that the event needed to be shut down and tried to disperse people, but some loitered, and then the shooting broke out, Mr. Onofri said.
The person who was killed, Tahaij Wells, 32, was believed to have been shot dead by the police and was one of multiple gunmen, officials said. One was hospitalized in critical condition, and another, identified as Amir Armstrong, 23, was arrested on weapons charges. Mr. Onofri said Mr. Wells had been in prison on “homicide-related charges” until February, when he was released on parole.
The authorities did not believe the festival was targeted.
Reed Gusciora, the mayor-elect, confirmed there had been unspecified threats of violence before the shooting. He said he had received a screenshot of a Facebook post on Sunday that said: “Please, please do not go to Art All Night! They will be shooting it up!”
Mr. Gusciora said he believed the police were aware of threats. “They were advised that there might be trouble,” he said, adding, “I don’t know if it was this specific post.”
For many Trenton residents, who have long endured entrenched issues with crime, poverty and drugs, the shooting was a blow to the city’s reinvigoration as an arts hub . The arts festival was a centerpiece of that effort.
Every year, the show is assembled virtually overnight, with submissions received on Friday and placed on the walls on Saturday.
“Everyone can put in one piece,” said Becke Singleton, who had volunteered at the event in the past. “It’s nonprofessional next to professional. Elderly next to a little child.”
This year, the art that covered the walls included portraits of Colin Kaepernick, the football player known for taking a knee during the national anthem, and an installation made by the New Jersey Chapter of Moms Demand Action for Gun Sense in America, which seeks gun control reforms.
“I grew up in this city and it’s always been rough,” said Gaby Fernández, 21, adding that she went to the festival because the paintings “made me feel proud.”
She said rumors of violence had circulated hours before the shooting but she still showed up with a friend shortly after 11 p.m.
“We both were warned that someone had planned to come and do harm but took the risk anyway,” she said. “I’ve been going to Art All Night for years and it’s always been a safe place.”
A.J. Rodriguez, 22, lives a couple of blocks from where the shooting happened. He said that when he heard the news, he was not surprised.
“It’s just regular around here,” he said. “I mean it’s every day. You think it’s going to be a good get-together and then everybody is beefing and not cool with each other.”
More than 25,000 people were projected to attend the festival, now in its 12th year. It was held at the Roebling Wire Works, once home to a factory that supplied wire cables for the Brooklyn and Golden Gate Bridges.
On Sunday afternoon, the authorities were roaming the cavernous building. Outside, the ground was littered with plastic cups and trash cans remained tipped over, their contents spilled to the ground.
Mr. Onofri said multiple weapons were recovered from the scene, including a handgun with an “extended capacity magazine” that could hold more ammunition than permitted under state law.
“It saddens me that a public attack such as this is what has brought major attention to our capital city on Father’s Day,” Mayor Eric Jackson said in a statement.
Luis Ferré-Sadurní reported from Trenton, and Mihir Zaveri from New York. Nick Corasaniti, Annie Correal and Jacey Fortin contributed reporting.