An aviation student from Saudi Arabia opened fire in a classroom building at the naval air station (Nas) in Pensacola, Florida, on Friday morning, a US official said, an attack the Saudi government quickly condemned and that US officials were investigating for possible links to terrorism.

The assault, which left three dead in addition to the assailant, was the second at a US navy base this week and prompted a massive law enforcement response and a lockdown at the base.

The shooter was a member of the Saudi military who was in aviation training at the base, the Florida governor, Ron DeSantis, said at a news conference. DeSantis spokesman Helen Ferre later said that DeSantis learned about the shooter’s identity from briefings with FBI and military officials.

A US official who spoke to the Associated Press on condition of anonymity identified the shooter as Mohammed Saeed Alshamrani. The official wasn’t authorized to discuss the matter publicly.

Earlier Friday, two US officials identified the student as a second lieutenant in the Saudi air force, and said authorities were investigating whether the attack was terrorism-related. They spoke on condition of anonymity to disclose information that had not yet been made public.

The New York Times reported that six other Saudi nationals, including three seen filming the attack, had been held for questioning, according to a source with knowledge of the investigation. There was no sign they were connected with the shooter, the paper reported.

Donald Trump tweeted that he had been fully briefed on the incident. “My thoughts and prayers are with the victims and their families during this difficult time. We are continuing to monitor the situation as the investigation is ongoing,” the president said. He declined to say whether the shooting was terrorism-related.

Trump added that Saudi leader, King Salman bin Abdulaziz Al Saud, had called him to express his condolences. “The King said that the Saudi people are greatly angered by the barbaric actions of the shooter, and that this person in no way shape or form represents the feelings of the Saudi people who love the American people,” Trump said.

The Saudi government issued a news release echoing Trump’s remarks.

DeSantis said the shooting demanded a response from Saudi Arabia.

“Obviously, the government ... needs to make things better for these victims,” he said. “I think they’re going to owe a debt here, given that this was one of their individuals.”

A national security expert from the Heritage Foundation warned against making an immediate link to terrorism.

“If there is some connection to terrorism, well, then that’s that,” said Charles “Cully” Stimson of the Heritage Foundation. “But let’s not assume that because he was a Saudi national in their air force and he murdered our people, that he is a terrorist.”

Stimson said it was also possible that the shooter was “a disgruntled, evil individual who was mad because he wasn’t going to get his pilot wings, or he wasn’t getting the qualification ratings that he wanted, or he had a beef with somebody, or there was a girlfriend involved who slighted him”.

The Florida Senator Rick Scott issued a scathing statement calling the shooting an act of terrorism “whether this individual was motivated by radical Islam or was simply mentally unstable”.

Scott added that it was “clear that we need to take steps to ensure that any and all foreign nationals are scrutinized and vetted extensively before being embedded with our American men and women in uniform”.

Twelve people were hurt in the attack, including two sheriff’s deputies who were the first to respond, one of whom killed the shooter, said David Morgan, the Escambia county sheriff. One of the deputies was shot in the arm and the other in the knee, and both were expected to recover, he said.

Lucy Samford, 31, said her husband, a navy reservist and civilian worker on the base, was about 500 yards from where the shooting happened. She said she got a call from him a little after 7am and “one of the first things out of his mouth was: ‘I love you. Tell the kids I love them. I just want you to know there’s an active shooter on base’.”

Her husband, whom she declined to identify, later told her he was OK.

Nas Pensacola employs more than 16,000 military and 7,400 civilian personnel, according to its website. One of the navy’s most historic and storied bases, it sprawls along the waterfront south-west of downtown Pensacola and dominates the economy of the surrounding area.

Part of the Pensacola base resembles a college campus, with buildings where 60,000 members of the navy, marines, air force and coast guard receive training each year in multiple fields of aviation.

The base is also home to the Blue Angels flight demonstration team, and includes the National Naval Aviation museum, a popular regional tourist attraction.

Alex McGinley, a tattoo artist who works near the Pensacola base, said he was alerted to the shooting by one of his clients, most of whom are military personnel. He said none of his clients was among those shot.

“What kind of things go through a person’s mind to a level that makes them do something like that?” McGinley asked.