A 24-year-old transit officer was stabbed in the neck when he tried to apprehend a man striking a woman below the Q train in Brooklyn on Thursday, authorities said.

Officer Filippo Gugliara was standing on the elevated platform by Ocean Parkway at about 1:15 p.m. when he heard the scuffle from the street below, Police Commissioner Bill Bratton said during a news conference from the hospital where Gugliara was recovering.

"He was brave: he pursued this perp, followed his training, did the right thing, went toward the danger," Mayor Bill de Blasio said after he and Bratton visited with Gugliara, his father, and his sister. "It was so good to see him, thank God, in great shape upstairs. This is an example to the city of the kind of men and women who join the NYPD. They're ready to serve, they're ready to walk into harm's way to make sure their fellow New Yorkers are safe."

Officials believe the 58-year-old suspect, who was not immediately identified, had gotten into an argument with a shop owner inside a nearby store. A 78-year-old woman then tried to intervene, but the suspect started arguing with her, Bratton said. The argument somehow spilled out onto the street.

When Gugliara heard the commotion below the tracks, he went down and tried to break it up. The suspect then stabbed him with an 11-inch hunting knife, which deflected off the shoulder of Gugliara's vest and went into his neck, Bratton said.

Gugliara, who joined the department in January 2013, then shot two rounds, striking the suspect in the torso. The 58-year-old man, who has one prior sealed arrest, was pronounced dead at the scene, Bratton said. The knife, he said, was found "a few inches from his hand."

During the attack, the 78-year-old woman was thrown onto the ground and injured, Chief of Detectives Robert Boyce said.

"That 78-year-old woman interceded in that and we believe that was the nexus of the assault on that woman" Boyce said. "We have the 78-year-old lady, we're speaking to her. We're seeking that merchant right now."

Gugliara was in stable condition at Lutheran Medical Center on Thursday evening, but would be held overnight, Bratton said.

"As you can see the officer was very fortunate," Bratton said. "The officer probably was saved by the fact that the knife seemed to initially have struck the officer's shoulder strap of his vest and deflected... [if it had] penetrated the officers neck, it would be a very different story."

Doctor Robert Davis, Lutheran's director of trauma and critical care, said Gugliara received a few stitches, but the wound was not very deep.

"A guy who just went through such a tough experience -- he was positive, he was proud of what he had done, and we told him how proud we were of him," de Blasio said. "Thank God the officer is well and he is an example to us all."

Gugliara was posted as part of an initiative that Bratton said he enacted when he was the chief of transit in the early 1990s. Joseph Fox, the current transit chief, said Gugliara was part of the "safe passageway" program.

"He was helping our young people get to and from school safely," Fox said. "We have officers specifically dedicated to these platforms, stations, and train lines."