BRIGHTON BEACH, Brooklyn -- A transit officer was breaking up a fight between a man and a 78-year-old woman Thursday when the man pulled out a knife and stabbed the officer, who opened fire and killed the attacker, police said at an afternoon news conference releasing more details about the deadly encounter.

"He was brave. He pursued this perp, followed his training and went toward the danger," Mayor Bill de Blasio said of the officer, a Brooklyn native who has been on the force since January 2013.

Officer Fillippo Gugliara, 24, was on foot patrol on an elevated Q train platform at the Ocean Parkway subway station, located near Sea Breeze Avenue and and West 1st Street in Brighton Beach, when he heard a commotion on the street, Police Commissioner William Bratton said.

When he went upstairs to see what was happening, the officer spotted a 58-year-old man fighting with a 78-year-old woman whom he did not know, Bratton said.

An initial investigation revealed the woman had intervened in an argument between the man and a nearby shop owner. The attacker then turned on her, ultimately pushing her to the ground, the commissioner said.

As the transit officer tried to break up the fight, the culprit pulled out an 11-inch knife and slashed him, Bratton said. He opened fire, striking and killing the attacker, who was pronounced dead at the scene. The weapon was recovered nearby.

The officer was rushed to a hospital where he was given stitches and is expected to be OK, a doctor said, saying the cut "wasn't that deep."

Surgeons credited that to the fact that the knife first hit the officer's shoulder strap on his vest which deflected the weapon, likely saving his life, Bratton said.

The culprit's name has not been released pending family notification, Bratton said. An NYPD official said the attacker "doesn't have much of a criminal history," citing one known prior arrest.