A gunman opened fire at a crowded mall outside Dallas on Saturday, killing at least eight people and injuring at least seven before a police officer killed him, the authorities said, turning a busy afternoon of shopping into a chaotic and tragic scene.

At a news conference Saturday night, Brian E. Harvey, the chief of police in Allen, Texas, did not identify a gunman but said the person acted alone. Chief Harvey said a police officer, who was on an unrelated assignment at the mall at the time of the shooting, heard gunfire, rushed toward it and killed the gunman.

A spokesman for Medical City Healthcare, which was treating several victims at three trauma facilities, said the ages of the injured ranged from 5 to 61.

The gunfire erupted around 3:30 p.m. at the Allen Premium Outlets as throngs of shoppers filled the outdoor mall, which is about 25 miles north of Dallas and has more than 120 stores. Videos circulating on social media show people dashing for shelter or running through a parking lot as loud popping noises can be heard in the background.

Seven people, including the gunman, were pronounced dead at the mall. Officials could account for at least nine people who were transported to hospitals, but more victims may have been taken in private vehicles, the Allen fire chief, Jonathan Boyd, said. Two of those died later. Three were in critical condition and four in stable condition.

A video circulating on social media appeared to show the gunman, lying on the ground, clad in black and equipped with what appeared to be a tactical vest, multiple rounds of ammunition and a long gun.

“We all want the victims and their families impacted by this tragedy to know that we will wrap our arms around you and we are here for you,” Ken Fulk, the mayor of Allen, said at a news conference. “We know you are grieving. We are grieving. Rest assured, the nation and the world are also grieving. Allen is a proud and safe city, which makes today’s senseless act of violence even more shocking.”

Mr. Fulk added that the police have been trained to not “hesitate to move toward the threat,” which most likely saved more lives.

Saturday’s attack is the second-deadliest shooting of the year, after the Monterey Park, Calif., massacre in which a gunman killed 11 people in a ballroom on Jan. 21.

According to the Gun Violence Archive, a database of shootings in the United States, there have been 199 “mass shootings,” which it defines as the shooting of at least four people, in 2023. There were a particularly deadly spate of large-scale shootings this past week.

Last weekend, a gunman killed five people in Cleveland, Texas, near Houston, after he was asked by neighbors to stop shooting in his yard. He was captured after a multiday manhunt.

On Monday, a registered sex offender fatally shot six people, including his wife and three of her children, near Tulsa, Okla., before turning the gun on himself.

On Wednesday, a gunman opened fire at a medical office building in Atlanta, killing one and injuring four others. That, too, led to a manhunt before the suspect was caught.

In Allen, Texas, witnesses described a familiar scene of pandemonium as gunfire erupted.

Geoffrey Keaton was having lunch with his 16-year-old daughter at Fatburger in the outlet mall when they heard gunshots.

“I immediately knew,” Mr. Keaton said. “I got my baby girl under the counter to shield her, and then they got louder, like he was right there.”

Mr. Keaton said the restaurant’s manager allowed customers to hide in the back, where they were able to exit through a rear door and run to their cars.

“You could see bodies of people he had shot on the sidewalk,” Mr. Keaton said.

A livestream from a local Fox television affiliate showed scores of shoppers being evacuated in an orderly fashion from shops like H&M, Michael Kors, American Eagle and Kay Jewelers.

Kaleo Palakiko, 36, was shopping with his parents for an upcoming vacation when they saw people running outside.

“It was just kind of chaotic for a second. Then when someone said, ‘shooter,’ we all ran to the back of the store,” Mr. Palakiko said. “As Americans, we’re used to this, because everyone knew exactly what to do.”

Mr. Palakiko and his parents hid in a storeroom for about 45 minutes before they were released by police and walked out with their hands in the air. Mr. Palakiko said they walked by stores with shattered window panes.

Brayson Jones, 17, had arrived early for his shift at the Champs Sports outlet store and was sitting in his car when he heard “probably 20-plus shots” and saw people running out of stores, he said.

Mr. Jones said a stranger ran toward his car and motioned to let him inside, and then the two drove away.

“As soon as I heard the shots and people yelling, I didn’t wait to see what was going on, I backed out and got out of there,” he said.

Four hours after the shooting, the police began to allow some people to retrieve their cars that were left behind at the outlet. Others, whose cars had been parked closer to the crime scene, would have to wait until tomorrow.

Representative Keith Self, a Republican who represents Allen, Texas, said on CNN that critics who are calling for more than “thoughts and prayers” after Saturday’s shooting “don’t believe in almighty God, who is absolutely in control of our lives.” Instead, he said, the country’s lack of “mental health institutions” is to blame.

“Really I would like to stay away from the politics today because I want to focus on the victims, today we should be focused on the families,” he said. “Prayers are important and they are important in the families that are devastated right now.”

In a statement, Kris Brown, the president of Brady, the gun violence prevention organization, noted the long list of shootings in a short week.

“A house, a doctors’ office, and now a mall,” he said. “These horrific tragedies are occurring with increasing regularity and it’s clear there’s no place in this country where Americans are safe from gun violence. But this will continue to be our reality unless and until the U.S. changes its relationship with guns and our lawmakers finally answer to the American people, not the gun lobby.”