An NYPD cop was shot in the head while off-duty Saturday night — and was clinging to life in the hospital Sunday morning, police said.

The officer — who police did not name — was trying to buy a car in East New York near the Brooklyn-Queens border from someone he met on social media around 7 p.m. when the purchase turned into a robbery, according to the NYPD.

“There was an exchange of gunfire where the off-duty officer was struck,” assistant NYPD chief Michael Baldassano said during a news conference hours after the shooting.

The cop has been with the NYPD for five years, and was with a relative when he was attacked, according to police. The suspect fled the location after the shooting and remains at large.

“Please keep this young officer in your prayers. He is currently fighting for his life,” Police Commissioner Keechant Sewell said during Saturday night’s press conference.

Baldassano said the attempted robbery was still under investigation, and police had “no reason to believe” the suspect knew the target was a police officer.

"My heart goes out to the family,” said Mayor Eric Adams. “My heart goes out to the members of the department in general, but specifically to the members of his command, to see a brother officer experience this."