He was pronounced dead at the scene, Detective Prieto said.

The police did not immediately say what prompted the shooting, or whether they had recovered any weapons or a bomb. The Miami-Dade County Police Department is investigating the shooting, and the F.B.I. and the Miami Beach Police Department are investigating the bank robbery attempt, Detective Prieto said.

The F.B.I. said the suspect was never given any money during the attempted holdup. Although he threatened to shoot a customer, no shots were fired and no one in the bank was injured, officials said. No device or object was left by the suspect, the agency said.

A representative for the county police did not return a phone call and an email seeking comment.

In an interview, Mr. Johnson, a local photographer who came upon the standoff during a coffee run before work, said he saw the suspect inside the barbershop banging on the glass with what appeared to be a sharp metal object and gesturing toward the police. Once the suspect came out, Mr. Johnson said, the police evacuated the shop’s employees and customers and gradually closed in on the suspect.

Mr. Johnson said the officers tried to calm the man, but he was not cooperative. About 50 people watched the encounter unfold from across the street, and several people recorded it on their cellphones, he said.

“You could feel the tension when you walked across the street, like something like that was going to happen,” said Mr. Johnson, who posted a clip of the video on Instagram.