For much of the last decade, the life of Jonathan Efraim had been punctuated by run-ins with the police and struggles to maintain mental stability. He was arrested at least 14 times, and once tried to commit suicide by drinking bleach.

His final encounter with the police, on Wednesday night, was fatal. After opening fire inside a crowded bar in Queens, he was shot and killed by two officers after he first shot at them, the authorities said.

The death of Mr. Efraim, 30, comes at a time of heightened scrutiny of police departments across the country after several deadly and highly publicized confrontations between white officers and black, often unarmed, men and people with mental illnesses. In New York City, protests erupted in December after a grand jury decided not to indict an officer caught on video using a chokehold to subdue Eric Garner, an unarmed black man who died after the encounter on Staten Island.

In the encounter on Wednesday, which resulted in New York’s first deadly police shooting of the year, officers appeared to follow department protocol and, initially, seemed to show restraint.