Mr. Laffer’s name caught the prosecutor’s attention because he lived in Medford and previously filled hydrocodone prescriptions at Haven Drugs, the official said, adding that the office also learned that Mr. Laffer had a pistol permit. The official said Ms. Brady had also filled oxycodone prescriptions, though there was no evidence she had ever filled them at Haven Drugs.

After comparing Mr. Laffer’s driver’s license photo with the images captured on the surveillance video at Haven Drugs, investigators in the Office of the Special Narcotics Prosecutor believed they had discovered a possible suspect, and passed on the information to the authorities in Suffolk County.

There are indications that Mr. Laffer had already come to the attention of the Suffolk authorities by then.

Mr. Laffer had served in the Army for seven years, discharged in 2002 as a private first class. Four years ago, he and Ms. Brady married at Giorgio’s on the North Shore of Long Island, after proposing to her at a hockey game.

He worked at Cosa Instrument in Yaphank, a company that produces and distributes measuring instruments, but he recently lost his job.

More than 1,800 pharmacy robberies have taken place across the country over the last three years, though few if any involved mass killings. Last year, the Suffolk County Police Department recorded eight robberies of pharmacies in the area it polices, which excludes some towns in the county. So far this year, there have been four, including the one on Sunday.

Two customers were fatally shot, Jaime Taccetta, 33, and Bryon Sheffield, 71; and so were two employees, Raymond Ferguson, 45, a pharmacist, and Jennifer Mejia, 17, a high school student.