The Saudi military student who killed three Americans at a US naval base in December had longstanding ties to al-Qaeda and planned an attack before he arrived in the United States, US justice officials said Monday.

The December 6 attack by Mohammed Alshamrani, a Royal Saudi Air Force flight student at the Naval Air Station Pensacola in Florida, "was actually the culmination of years of planning and preparation," said FBI Director Christopher Wray.

Evidence discovered on an encrypted cellphone shows he was radicalized at least as far back as 2015, and has since been associating with "dangerous" operatives from the Yemen-based Al-Qaeda in the Arabian Peninsula (AQAP), Wray added.

The FBI and Justice Department revealed their findings after a months-long effort to crack the encryption on Alsahamrani's iPhones, which they said Apple refused to help with.

The December 6 attack by Saudi Royal Air Force 2nd Lieutenant Mohammed Alshamrani involved years of planning, says the FBI
The December 6 attack by Saudi Royal Air Force 2nd Lieutenant Mohammed Alshamrani involved years of planning, says the FBI FBI / Handout

US Attorney General Bill Barr accused Apple of putting its own financial interests ahead of the nation's in refusing to provide US investigators a way to break encrypted phones.

"If not for our FBI's ingenuity, some luck, and hours upon hours of time and resources, this information would have remained undiscovered," Barr said.

"The bottom line: our national security cannot remain in the hands of big corporations who put dollars over lawful access and public safety. The time has come for a legislative solution," he said.

FBI Director Christopher Wray says encrypted files on Alshamrani's cell phone showed his ties to al-Qaeda
FBI Director Christopher Wray says encrypted files on Alshamrani's cell phone showed his ties to al-Qaeda GETTY IMAGES NORTH AMERICA / MARK WILSON

Wray said the 21-year-old-Saudi had expressed a desire to learn to fly years ago with plans for a "special operation," enlisting in the Royal Saudi Air Force and joining flight training in the United States.

"In the months before the attack, while he was here among us, he talked with AQAP about his plans and tactics -- taking advantage of the information he acquired here, to assess how many people he could try to kill," Wray said.

The December 6 shooting in a classroom building at the naval base left three US sailors dead and wounded eight other people, including two responding sheriff's deputies, before Alshamrani was killed by police.

AQAP claimed responsibility, but there was no immediate evidence of a direct link.

The incident forced the temporary freeze of all US training for foreign military officials to review security precautions.

The decades-old US-Saudi training program has been crucial to the close relationship, with thousands of Saudis undergoing military training in the United States.

The US expelled 21 of Alshamrani's classmates for reasons including that some had allegedly been aware of his radical leanings and others possessed jihadist material and child pornography.

The program has since resumed, but with heavier vetting of Saudi students, and a ban on them accessing firearms.