An NYPD officer was shot in the back in Brooklyn on Thursday night — and might have been saved when the bullet struck the rear armor of his protective vest, law-enforcement sources said.

The 27-year-old officer was responding to a domestic dispute in Crown Heights just after 9 p.m. when the gunman opened fire, police sources told the New York Post.

The suspect, identified by police as William Moss, was on his way to his girlfriend’s house when he allegedly told her that he had a gun and was going to open fire when he got there, the sources said. Cops arrived at the residence after the girlfriend’s mother called 911.

The officers were talking to the younger woman when Moss arrived, shot the officer and fled, according to the sources.

Moss was apprehended by other officers after a short foot pursuit. Officers reportedly fired on the suspect, but he was not hit. It's not known if the suspect returned fire.