A Saudi trainee military pilot reportedly condemned the United States as a "nation of evil" before carrying out a mass shooting at a top US Navy base in Florida.
Lieutenant Mohammed Saeed Alshamrani killed three people and injured eight before being shot dead himself by police at the Naval Air Station Pensacola.
The Saudi Air Force officer, who was on a US-sponsored training programme, reportedly posted a manifesto on Twitter in which he wrote: "I'm against evil, and America as a whole has turned into a nation of evil."
It went on: "I'm not against you for just being American, I don't hate you because your freedoms, I hate you because every day you supporting, funding and committing crimes not only against Muslims but also humanity."
According to the the SITE intelligence group, which monitors jihadist activity, the messages were posted hours before the shooting, and quoted Osama bin Laden.
The FBI was investigating whether the postings were made by Alshamrani, and whether he was part of a wider group.
Agents detained six other Saudis for questioning, three of whom reportedly started filing after the attack. It was not clear whether they had any connection to the gunman or were just at the scene.
The sprawling Naval Air Station Pensacola is the site of the US National Naval Aviation Museum, and the base of the Blue Angels flight demonstration team.
It is referred to as the home of US naval aviation and hundreds of pilots from allied nations pass through for training at any one time.
Military personnel are not allowed to carry weapons on the base but Alshamrani was able to take a Glock handgun, purchased locally, into a classroom building where trainee pilots were studying.
His training at the base began in August 2017 and was due to finish in August 2020.
He was also armed with up to six extended magazines, meaning he could have caused far greater carnage had he not been shot by sheriff's deputies who rushed to the scene.
Saudi Arabia sought to distance itself from the incident as it seeks to repair its image of being an exporter of Islamic extremism.
Fifteen of the 19 hijackers in the September 11, 2001 attacks were Saudis, including some who gained civilian flight training in the US.
Last year, the Washington Post columnist Jamal Khashoggi was killed at the Saudi consulate in Istanbul.
King Salman telephoned Donald Trump to denounce the Florida shooting as "heinous" and to pledge cooperation over investigating it.
Prince Khalid bin Salman, the king's younger son and deputy defence minister, said: "Like many other Saudi military personnel, I was trained in a US military base, and we used that valuable training to fight side by side with our American allies against terrorism and other threats."
However, Florida Governor Ron DeSantis suggested Riyadh should offer compensation to the victims, saying they "owe a debt".
US officials said Saudi Air Force officers undergoing military training in the US were intensely vetted, "hand-picked," and often came from elite families.
But Mark Esper, the US defence secretary, said vetting procedures would be reviewed. He said: "Are we screening persons coming to make sure they have their life in order, their mental health is adequate?"
There are currently 5,000 foreign aviation students from 153 countries in the US, including hundreds of Saudis.
Captain Timothy Kinsella, the Pensacola base commander, said: "The cross-training with allies is something that we have done for a long time. In World War II, we had Royal Air Force folks training here."
Alshamrani reportedly held a dinner party in the days before the shooting, at which he and three others watched videos of mass shootings.
One of the three men who attended the dinner party then filmed outside the building while the Pensacola shooting was taking place, according to a US official.
One victim was named as Joshua Kaleb Watson, 23, a recent graduate of the US Naval Academy.
His brother Adam Watson said that, despite being shot several times, he made it outside and alerted the response team to where the gunman was. Mr Watson said: “He saved countless lives today with his own. He died a hero.”