NEW YORK - (AP) -- A 25-year-old police officer shot in the head while attempting to stop a man suspected of carrying a handgun died Monday from his injuries, the third New York City officer slain on duty in five months.

Brian Moore, who was in a coma after undergoing brain surgery following the Saturday evening shooting, was pronounced dead at a Queens hospital with his family, including his police officer father, uncle and cousin, at his bedside.

Hundreds of uniformed officers stood at attention outside the hospital and lined up down the block to salute the ambulance carrying his body. Afterward, many could be seen crying and consoling one another.

"He proved himself to be an exceptional young officer," Police Commissioner William Bratton said, noting Moore had made more than 150 arrests in less than five years on the job and earned meritorious service medals.

Moore and his partner were in plainclothes and in an unmarked police car when they approached Demetrius Blackwell in a quiet Queens neighborhood after they saw him adjusting his waistband, a move that made them suspicious he had a handgun, authorities said.

The officers pulled up next to Blackwell, 35, and exchanged words before the man suddenly turned, pulled out a weapon and fired at least twice at them, striking Moore in the head and face, according to court documents.

Blackwell has been charged with attempted murder and other crimes. He is being held without bail and has not entered a plea. His attorney has denied the charges.

He will be charged with first-degree murder, prosecutors said.

Investigators discovered the five-shot silver Taurus used in the shooting under a box near a backyard grill along the route Blackwell fled following the shooting, Chief of Detectives Robert Boyce said.

The gun, which had two live rounds still in the chamber, was one of 23 weapons reported stolen in October 2011 from a bait and tackle shop in Perry, Georgia, he said. Ten of those weapons have since been recovered -- nine of them in in New York.

Mayor Bill de Blasio mourned Moore's death.

"He risked his life for a very simple notion -- to keep everyone else safe, to keep our society safe, to keep order," the mayor said at an evening news conference. "This is what he wanted to do."

Patrick Lynch, who heads the rank-and-file police officers' union, joined Moore's family at the hospital and told reporters afterward that the city's police force would pay their respects, and then return to their posts patrolling streets, stairwells and subways.

"They may have sadness in their eyes, but they have bravery in the hearts," he said.

Moore had been on the job since July 2010, officials said. Flags at police headquarters were flying at half-staff Monday.

He is the first city officer to be killed on duty since two uniformed police officers were slain in December in Brooklyn.

Officers Wenjian Liu, 32, and Rafael Ramos, 40, were shot at close range as they were sitting in their patrol car Dec. 20. The gunman, 28-year-old Ismaaiyl Brinsley, then ran into a nearby subway station and fatally shot himself.

Before the ambush, Brinsley posted on an Instagram account that he was planning to shoot two "pigs" in retaliation for Eric Garner's death in an apparent police chokehold.

Officials have said Blackwell made no such postings and had an extensive criminal history, including serving five years in prison on an attempted murder conviction.

___

Associated Press writer Jonathan Lemire contributed to this report.