LOS ANGELES — A 23-year-old man wielding an assault rifle and carrying 100 rounds of ammunition shot and killed a Transportation Security Administration officer at Los Angeles International Airport on Friday morning, sending travelers fleeing in panic and paralyzing one of the world’s busiest airports for hours.
Two other people, one of them a security agent, were shot, and at least four others were injured in the melee.
The gunman entered Terminal 3 just before 9:30 a.m., pulled a weapon from a bag, and began firing as he forced his way through a security checkpoint, officials said. Airport police officers chased him through the bustling terminal as he continued to fire, before shooting him near a departure gate and arresting him.
The TSA agent who was killed was the first to die in the line of duty since the agency was created in the aftermath of the Sept. 11 terrorist attacks, officials said.
Thousands of travelers throughout the airport were evacuated, and flights were grounded for hours, with some incoming flights diverted to nearby airports and others held on the tarmac while the shooting unfolded.
Passengers spent hours in waiting areas, parking lots, and nearby hotels as they waited for flights to resume. Air traffic across the country was stalled in a ripple effect.
US officials identified the gunman as Paul Ciancia, 23, of Los Angeles, who had previously lived in New Jersey. A senior federal official said that he had a note with “antigovernment and anti-TSA ramblings.”
Ciancia was being treated at a Los Angeles hospital, officials said.
Rich Garry, 68, of Fullerton, Calif., said he had been at Terminal 3 on Friday morning headed for a flight to New York to visit family members. He said that a security officer had just checked his boarding pass, and that he was waiting in line at the security checkpoint when he heard two shots.
“I heard a ‘pop-pop’ and I looked down a floor below, and the TSA guy was on the floor,” he said. “He had been shot.”
Garry said he believed it was the security officer who had inspected his boarding pass.
As the gunman moved through the terminal, Garry said, “He was very calm. When he got to the top of the stairs where the security checkpoints are, he looked around. If he would have come up the ramp, he would have had a field day with all the people lying on the ground, like me.”
Garry said he and several others had crawled to a nearby elevator and got off on the ground floor. Once there, he saw police officers for the first time, and told them to go to the second floor.
Joseph James, 32, who said he had just gotten off a flight in Terminal 3 and was leaving the building when he heard several shots behind him, said, “Several people were yelling, ‘Bomb! Bomb!’ and that’s what terrified me the most.”
Leon Saryan, a traveler from Milwaukee, told Milwaukee radio station WTMJ: “I was in the hallway cowering when the guy came through. And he had a rifle in his hand and he looked at me and he said ‘TSA?’ And I shook my head and he just kept going.”
Many passengers dropped their bags as they rushed away from the terminal, leaving police officers with hundreds, if not thousands, of bags that they needed to screen.
At a news conference Friday evening, Mayor Eric Garcetti of Los Angeles said the gunman had had at least 100 rounds “that could have literally killed everyone in that terminal.”
A spokeswoman at Ronald Reagan UCLA Medical Center said that the hospital had admitted three male patients, two with gunshot wounds.
One of the men who had been shot was in critical condition and the two others were in fair condition.
The TSA identified the slain agent as Gerardo I. Hernandez, 39. Officials said he was working as a behavior detection officer, responsible for spotting suspicious activity.
Airport officials said 746 flights were affected by the shutdown, and 46 flights were diverted to other airports. They said the backups would not be resolved quickly, and advised passengers using Terminal 3 to check with their airlines Saturday to see whether operations had resumed.
The shooting was bound to raise new questions about security procedures at US airports.
“This shows what kind of risks our agents take,” said J. David Cox, president of the union representing TSA agents.
Airport police and the Los Angeles Police Department had undergone training in recent weeks in how to respond to a shooting, said Chief Patrick M. Gannon of the airport police.
The shooting caused panic among travelers, who threw themselves to the ground on orders from the police, then rushed in every direction, shouting “Run, run!” from what they believed could be a terrorist attack.
Massport, which runs Logan International Airport in Boston, said in a statement that it was “monitoring the situation in Los Angeles with our law enforcement partners in the intelligence community.”
Officials declined to elaborate on how security at Logan adapted to the events in Los Angeles.
“We don’t talk about what we do as far as security,” said Matthew Brelis, a spokesman for Massport. “It’s multilayered and it’s constantly changing.”Globe correspondent Nicholas Jacques contributed to this report.