NEW YORK — Hofstra University students wore white ribbons at their graduation ceremony Sunday to honor a 21-year-old student who was accidentally killed by a police officer two days earlier.

Andrea Rebello was killed after a masked man walked through the unlocked door of her off-campus home. An officer aiming at the would-be robber opened fire, hitting the Hofstra junior as well as the ex-convict, who was holding her in a headlock.

The officer who fired the shots is an eight-year veteran of the New York Police Department and has been with Nassau County police for 12 years. He is now out on sick leave.

Criminal justice analysts said the officer faced perhaps the most harrowing decision of a law enforcement career: choosing the split-second moment when the risk is so high that you must act to save a life.

‘‘The big question is, how do you know, when someone’s pointing a gun at you, whether you should keep talking to them, or shoot?’’ said Michele Galietta, a professor of psychology at the John Jay College of Criminal Justice who helps train police officers.