SAN FRANCISCO—A man flashed a gun several times on a crowded commuter train in San Francisco, but passengers were so absorbed in their phones and tablets they didn’t notice until he randomly shot and killed a university student, authorities said.

Security video footage showed the gunman pull out the .45-calibre pistol, raise it and point it across the aisle before putting it back against his side, authorities told the San Francisco Chronicle in a story on Monday.

The man drew the gun several more times and once wiped his nose with the hand holding the weapon.

“These weren’t concealed movements. The gun is very clear,” district attorney George Gascon said. “These people are in very close proximity with him, and nobody sees this. They’re just so engrossed, texting and reading and whatnot. They’re completely oblivious of their surroundings.”

Authorities declined a request for the surveillance footage, citing an ongoing investigation.

San Francisco police officials say people who pay too much attention to digital technology are also vulnerable to theft.

“Oftentimes when you interview people who get their phones stolen, when you ask them to describe where the person came from, what he was wearing, they have no idea,” said police Chief Greg Suhr.

Nikhom Thephakaysone, 30, has pleaded not guilty to charges including murder in the Sept. 23 attack on Justin Valdez, 20, a student at San Francisco State University who was shot in the back of the head as he left the train.

Thephakaysone also has been charged with assault with a semi-automatic handgun. Prosecutors said he stuck a handgun in another man’s back earlier the same night he shot Valdez as he looked for a victim.

He did not pull the trigger and went on the hunt again for a victim for more than an hour, at one point waving a gun outside a Thai restaurant, assistant district attorney Scot Clark has said.

He was also charged with illegally possessing an assault weapon after police said they seized two such rifles, combat knives and razors at his home.

Police said he was carrying $20,000 in cash when he was arrested.