FORT LAUDERDALE, Fla. — An Army veteran who complained that the government was controlling his mind drew a gun from his checked luggage on arrival at the Fort Lauderdale airport and opened fire in the baggage claim area Friday, killing five people and wounding eight, authorities said.

He was taken into custody after throwing his empty weapon down and lying spread-eagle on the ground, one witness said.

“People started kind of screaming and trying to get out of any door they could or hide under the chairs,” the witness, Mark Lea, told MSNBC. “He just kind of continued coming in, just randomly shooting at people, no rhyme or reason to it.”

The gunman was identified as 26-year-old Esteban Santiago of Anchorage, Alaska, who served in Iraq with the National Guard but was demoted and discharged last year for unsatisfactory performance. His brother said he had been receiving psychological treatment recently.

A law enforcement official told The Associated Press that Santiago had walked into the FBI office in Anchorage in November to say that the U.S. government was controlling his mind and making him watch Islamic State videos.

Agents questioned an agitated and disjointed-sounding Santiago and then called police, who took him for a mental health evaluation, according to the official, who was not authorized to discuss the case and spoke on condition of anonymity.

FBI agent George Piro, who is in charge of the Miami field office, confirmed that Santiago had come into the Anchorage office and said he clearly indicated at the time that he was not intent on hurting anyone.

Authorities said the motive for the attack was under investigation. Shortly after the shooting, and before details of Santiago’s mental health became public, Sen. Bill Nelson of Florida said that it remained to be seen whether it was terrorism or the work of “someone who is mentally deranged.”

Piro said authorities are looking at leads in several states and have not ruled out terrorism. “We’re looking at every angle, including the terrorism angle,” he said

Santiago, who is in federal custody, will face federal charges and is expected to appear in court Monday, Piro said.

One witness said the attacker gunned down his victims without a word and kept shooting until he ran out of ammunition for his handgun, sending panicked travelers running out of the terminal and spilling onto the tarmac, baggage in hand.

Others hid in bathroom stalls or crouched behind cars or anything else they could find as police and paramedics rushed in to help the wounded and establish whether there were any other gunmen.

Bruce Hugon, who had flown in from Indianapolis for a vacation, was at the baggage carousel when he heard four or five pops and saw everyone drop down on the ground. He said a woman next to him tried to get up and was shot in the head.

“The guy must have been standing over me at one point. I could smell the gunpowder,” he said. “I thought I was about to feel a piercing pain or nothing at all because I would have been dead.”

It is legal for airline passengers to travel with guns and ammunition as long as the firearms are put in a checked bag — not a carry-on — and are unloaded and locked in a hard-sided container. Guns must be declared to the airline at check-in.

Santiago arrived in Fort Lauderdale after taking off from Anchorage aboard a Delta flight Thursday night, checking only one piece of luggage — his gun, said Jesse Davis, police chief at the Anchorage airport.

At Fort Lauderdale, “after he claimed his bag, he went into the bathroom and loaded the gun and started shooting. We don’t know why,” said Chip LaMarca, a Broward County commissioner who was briefed by investigators.

The bloodshed is likely to raise questions of whether aviation safety officials need to change the rules.

The attack also exposed another weak point in airport security: While travelers have to take off their shoes, put their carry-on luggage through X-ray machines and pass through metal detectors to reach the gates, many other sections of airports, such as ticket counters and baggage claim areas, are more lightly secured and more vulnerable to attack.

In 2013, a gunman with a grudge against the Transportation Security Administration shot and killed one of the agency’s screeners and wounded three others during a rampage at Los Angeles International Airport. Last November, an airline worker was shot and killed near an employee parking lot at Oklahoma City’s airport, and in 2015 a machete-wielding man was shot to death after he attacked federal security officers at the New Orleans airport.

“The fact is that wherever there are crowds, such as at our airports, we remain vulnerable to these types of attacks,” Nelson said.

The Fort Lauderdale gunman said nothing as he “went up and down the carousels of the baggage claim, shooting through luggage to get at people that were hiding,” according to Lea. The killer went through about three magazines before running out of ammunition, Lea said.

“He threw the gun down and laid spread-eagle on the ground until the officer came up to him,” Lea said.

The gunman was arrested unharmed, with no shots fired by law enforcement officers, and was being questioned by the FBI, Sheriff Scott Israel said.

Broward County Sheriff Scott Israel said 30 to 40 people were injured — scrapes, bruises and broken bones — after the shooting.

The condition of the wounded was not disclosed. At least one of the victims was seen lying in a pool of blood with what appeared to be a head wound.

The airport was shut down, with incoming flights diverted and outgoing flights held on the ground. Airport Director Mark Gale said it will try to reopen at 5 a.m. Saturday but urged travelers to check with their individual airlines on flight status. He said 10,000 of the airport’s stranded travelers were being bused overnight to the city’s spacious Port Everglades cruise ship terminal.

President Barack Obama was briefed by his Homeland Security adviser, the White House said. President-elect Donald Trump said that it is a “disgraceful situation that’s happening in our country and throughout the world” and that it was too soon to say whether it was a terrorist attack.

Santiago’s brother, Bryan, told the AP that his brother had been receiving psychological treatment in Alaska. He said Santiago’s girlfriend alerted the family to the situation in recent months. Bryan Santiago said that he didn’t know what his brother was being treated for and that they never talked about it.

He said Esteban Santiago was born in New Jersey and moved to Puerto Rico when he was 2. He was sent to Iraq in 2010 and spent a year there with the 130th Engineer Battalion, according to Puerto Rico National Guard spokesman Maj. Paul Dahlen. He later joined the Alaska National Guard.

The Pentagon said Santiago had gone AWOL several times during his stint with the Alaska National Guard and was demoted — from specialist to private first class — and given a general discharge, which is lower than an honorable discharge.

John Schilcher told Fox News he came up to the baggage claim and heard the first gunshot as he picked up his bag off a carousel.

“The person next to me fell to the ground and then I started hearing other pops. And as this happened, other people started falling and you could hear it and smell it, and people on either side of me were going down and I just dropped to the ground,” said Schilcher, who was there with his wife and mother-in-law. “The firing just went on and on.”

“I was down on the floor. When we finally looked up there was a policeman standing over me,” he said. “That’s when I assumed it was safe.”