PENSACOLA, Fla. — The Saudi air force trainee who killed three classmates at a Florida Navy base last week was a gifted student whose personality appeared to change after a trip to his native country this year, acquaintances and officials familiar with the case said Monday.

Ahmed Mohammed al-Shamrani was described as “strange” and “angry” in the weeks leading up to Friday’s shooting rampage, but schoolmates and other acquaintances said he showed no outward sign that he was preparing to open fire inside a classroom building where he had been training to become a military aviator. The shooting, which also left eight people injured, is being treated by the FBI as a possible terrorist attack.

“He looked like he was angry at the world,” said the owner of an Indian restaurant that Shamrani and several other Saudi students regularly patronized between classes. The man, like several other businesses owners, spoke on the condition that neither his name nor the restaurant’s name be revealed, citing fears of a backlash from customers.

While the FBI has not yet determined a motive for the mass shooting, investigators are building a profile of the gunman from interviews with dozens of acquaintances, including fellow Saudi students, as well as from a Twitter account that authorities say belonged to Shamrani. The gunman, who was shot dead by a sheriff’s deputy responding to the shooting, is thought to have written a “will” that was posted to the account a few hours before the rampage. In it, he blasts U.S. policies in Muslim countries. The document makes no references to any particular terrorist group.

Shamrani was among hundreds of foreign students training at the Naval Air Station in Pensacola. He had completed two years of schooling in the United States and was expected to graduate from the program in the summer.

A Saudi government official familiar with Shamrani described the 21-year-old as “an A student” who was “well-liked and kept to himself.” The official said the Saudi government was unaware of a formal complaint filed by Shamrani in April in which he accused an instructor of humiliating him by calling him a derogatory nickname in front of other classmates. The incident was first reported by the New York Times. The FBI on Monday declined to comment on the reported ill will between Shamrani and one of his instructors.

The depiction of Shamrani as generally mild-mannered echoed accounts given to investigators by several of Shamrani’s classmates, who described him as quiet and reserved, rarely speaking during classes.

But his demeanor seemed to change following a recent home leave, several students said, with Shamrani becoming more withdrawn and often appearing sullen, officials familiar with the matter said.

Local business owners had a similar impression. The owner of one Pensacola eatery said Shamrani visited his restaurant at least once in the week before the shooting. The owner described him as “strange,” “quiet” and “angry.”

“To us, he was not normal,” the businessman said. He recalled that Shamrani stared at him and his staff in an “angry, challenging” way. But he also noted that Shamrani showed no obvious signs of religious extremism, refraining, for example, from asking if the restaurant served halal meat eaten by observant Muslims.

The owner of the Indian restaurant said Shamrani was among a group of seven or eight Saudis who would visit his establishment as often as twice a week, usually after attending Friday prayers. The men would spend freely and nearly always order the same meal, an assortment of dishes including lamb chops, chicken and shrimp.

The man specifically remembered seeing Shamrani about a week before the shooting and recalled that he had been rude with his staff.

When the Saudis failed to show up as usual on Friday, he wondered what had happened to them. He understood when he saw news on television about the shooting at the Navy base, he said.

Several of the business owners said law enforcement officials have visited them in the days since the shooting.

None of the acquaintances recalled Shamrani discussing religion or politics. But FBI officials were drawing insights from the alleged gunman’s Twitter account. The typo-filled will apparently posted by Shamrani is addressed to the “American people.” The writer says he does not dislike Americans per se — “I don’t hate you because of your freedoms,” he begins — but that he hates U.S. policies that he views as anti-Muslim and “evil.”

“What I see from America is the supporting of Israel, which is invasion of Muslim countries,” the letter states. “I see invasion of many countries by its troops. I see Guantánamo Bay. I see cruise missiles, cluster bombs and UAV.”

The posting has been widely circulated on Islamist websites, though no group has issued a credible claim of sponsoring or encouraging Shamrani’s actions.

Also Monday, a senior defense official, speaking on the condition of anonymity because of the sensitivity of the issue, said the Navy was beginning to discuss the possibility that the sailors killed and wounded in Pensacola could merit Purple Heart medals and that some of them could be eligible for some sort of valor award.

The issue will depend on what determination the FBI makes about the case, the official said. The service members could be eligible for the Purple Heart if the service determines that the attack was inspired by a foreign terrorist organization, based on guidelines for the award.

In 2016, the military awarded Purple Hearts to service members who were killed or wounded in a July 2015 attack at a recruiting center in Chattanooga, Tenn.

The criteria to receive one were expanded in 2015 through congressional action to include service members wounded stateside in acts of terrorism after years of lobbying in response to two attacks on military facilities in 2009. In one, 13 people were killed and more than 30 were wounded at Fort Hood, Tex. In the other, two service members were killed in a shooting at a recruiting center in Little Rock.

Warrick reported from Washington. Dan Lamothe and Mark Berman contributed to this report.