ORANGE -- Officials on Tuesday identified the man who was fatally shot by a detective near the Orange train station after authorities say he had a gun, robbed a bank and refused orders from police.

Scott Mayfield, 24, of East Orange, was shot by an Essex County Sheriff's detective after the bank robbery around 5:30 p.m. Thursday at the PNC branch on Main Street, according to officials. The detectives were investigating drug complaints in the area when they heard a police radio broadcast about the robbery and encountered the suspect, later identified as Mayfield.

"They came upon the suspect, identified themselves as police officers, ordered the suspect, who was armed with an apparent handgun, to stop," Essex County Chief Assistant Prosecutor Thomas Fennelly told reporters in a briefing at the shooting scene. "The suspect refused commands of the officers."

Police would not say what kind of gun Mayfield had at the time of the shooting.

A detective fired his weapon during the encounter, Fennelly said. Investigators recovered the weapon and a bag of stolen money.

The shooting unfolded near an apartment building and commuter rail stop off Orange's Main Street business district. Detectives with the sheriff's department rushed to assist local police when the robbery occurred.

"They happened to be on the scene at the right time in the right place," said Sheriff Armando Fontoura. "This is what we do as police officers. Sometimes we are called to do things that we are not fond of, but we do what we need to do."

Essex County Prosecutor's Office spokeswoman Katherine Carter on Tuesday did not release additional details on the robbery, citing the ongoing investigation. The prosecutor's office was awaiting ballistic test results on the weapon, she said.

Under state Attorney General's Office guidelines, county prosecutor's offices must investigate incidents where a police officer fires a weapon.