PENSACOLA, Fla. — A Saudi aviator in training pulled out a handgun in a classroom at the Naval Air Station Pensacola early Friday and opened fire, killing three and injuring eight before a deputy fatally shot him, authorities said.

President Donald Trump, who spoke with King Salman of Saudi Arabia shortly after the shooting, said the monarch called the attack "barbaric."

The shooter was identified as Mohammed Saeed Alshamrani, a member of the Saudi military, according to a Defense official who spoke to USA TODAY on condition of anonymity.

A motive for the attack is unknown. All of the shooting took place in one classroom, where Alshamrani was being trained as part of a Pentagon security cooperation agreement with the Kingdom of Saudi Arabia, authorities said.

Alshamrani was one of 852 Saudi nationals in the United States training under the program, the Defense official said. Alshamrani, began his three-year course in August 2017 with English, basic aviation and initial pilot training.

The shooting began around 6:30 a.m. CT and the suspect was halted by two Escambia County sheriff's deputies, who arrived on scene in less than five minutes, Sheriff David Morgan said. One of the deputies fatally shot the gunman, he said.

An official who was not authorized to speak publicly told USA TODAY that the Saudi national did not use his military-issued service weapon.

One of the officers was shot in arm and treated at a local hospital. The other was shot in the knee and was undergoing surgery. Authorities expected both to survive.

"The best of our community was on scene today and that's why it turned out the way it did," Morgan said of the deputies who responded. "They ran to the fight, not from the fight."

Morgan said his deputies train regularly with base personnel for the type of attack that they encountered.

Defense Secretary Mark Esper said he and others are watching the situation closely.

Story continues

"I've spoken with the Secretary of the Navy, and Deputy Secretary (David) Norquist and am considering several steps to ensure the security of our military installations and the safety of our service members and their families," Esper said. "I'm grateful for the heroism of the first responders and law enforcement who helped confront both situations and kept further loss of life from occurring."

The latest: Here's what we know about the shooting at NAS Pensacola

The FBI has taken the lead in the investigation, though there has been no immediate determination on whether the shooting was terror related, two sources told USA TODAY.

The shooting was the second in a week at a U.S. Navy base.

Navy Adm. Mike Gilday, chief of naval operations, said it has been "a devastating week for our Navy family."

"Our hearts break for those who lost their lives in Pensacola and the wrenching pain it causes their loved ones," he said. "When tragedy hits, as it did today, and Wednesday in Pearl Harbor, it is felt by all."

Like most military installations, personal firearms are not normally permitted on the base, which provides a wide variety of training to both U.S. and international aviators, dating back to the British Royal Air Force during WWII.

The Pensacola base is also home of the Blue Angels, the Navy's Flight Demonstration Squadron, and the National Naval Aviation Museum. Located in the far western Panhandle, the base employs more than 16,000 military and 7,400 civilian personnel.

The U.S. has long had a robust training program for Saudis, providing assistance in the U.S. and in the kingdom. The shooting, however, shined a spotlight on the two countries’ sometimes rocky relationship.

Florida Gov. Ron DeSantis, a Navy veteran, asked all Americans to remember the dead and wounded, along with their families: "They need your prayers and they need your comfort."

Eight patients, including the deputies, were taken to nearby Baptist Hospital. One of the victims died at the hospital, and two died on the base. The shooter also died on the base. The names of the victims will not be released until the next of kin have been notified, authorities said.

"Walking through the crime scene was like being on the set of a movie," Morgan said. "This doesn't happen in Escambia County. This doesn’t happen in Pensacola . . . So now we’re here to pick up the pieces."

The shooter was in aviation training at the base, along with "several hundred" other international airmen, authorities said. DeSantis said the shooter's nationality will complicate the investigation.

"Obviously, the government of Saudi Arabia needs to make things better for these victims," DeSantis said in a press conference. "They’re going to owe a debt here."

Added Pensacola Mayor Grover Robinson: "This is a tragic day for the city of Pensacola. "We’re a military town. Our hearts and prayers are connected to those that serve us every day."

The shooting came two days after a U.S. Navy sailor shot three people and then killed himself at Pearl Harbor.

USA TODAY's Grace Hauck reported from Chicago and Kevin Johnson from Washington, D.C., with Trevor Hughes in Denver; Pensacola News Journal's Annie Blanks reported from Pensacola, Florida. Tom Vanden Brook in Washington also contributed to this report.

'This is mercy, not justice': Las Vegas shooting victims to split $800M. But how much is pain worth?

'The loneliest club': For survivors caught in endless loop of mass shootings, time doesn't always heal

This article originally appeared on USA TODAY: Pensacola shooting: Saudi national dead after shooting 3 at NAS base