A plainclothes New York City police officer was recovering from surgery Sunday after being shot in the head after questioning a man he saw acting suspiciously.

Officer Brian Moore, 25, was seated in an unmarked police car with his partner Officer Erik Jansen in the Queens Village when he saw the man walking and adjusting something in his waistband, police Commissioner William Bratton said.

Officer Moore inquired about the man’s actions and the suspect removed a firearm from his waistband, turned to the officers and fired into the vehicle, hitting Officer Moore in the head, Bratton said, speaking at a news conference at Jamaica Hospital in Queens, where Officer Moore was undergoing treatment Saturday night.

“Both officers were still seated in the vehicle and did not have an opportunity to get out or return fire,” he added.

The incident happened around 6.15 pm Saturday.

The suspect — 35-year-old Demetrius Blackwell — fled to an alley and on to 104th Road, and Officer Jansen radioed for assistance, Bratton said.

He said Blackwell was taken into custody about 90 minutes later. No weapon was found and, as of early Sunday, Blackwell had not been charged, the Associated Press reported.

Bratton said Blackwell has an extensive arrest history, including criminal possession of a weapon and robbery.

Officer Moore, who comes from a police family, joined the department in July 2010.

Speaking at the news conference, de Blasio said: “This was an unconscionable act of violence, not just against one police officer, but against the city of New York and against the values we hold dear.

“Our hearts are with his family, his loved ones — our hearts are with his extended family, the men and women of the NYPD.”

The incident comes five months after New York City police officers Wenjian Liu and Rafael Ramos were shot to death as they sat in their patrol car in Brooklyn in December.

The gunman, Ismaaiyl Brinsley, who was found dead of a self-inflicted gunshot wound, had posted anti-police messages on social media after the deaths of two unarmed black men, Michael Brown of Ferguson, Mo., and Eric Garner of Staten Island, N.Y., during confrontations with white police officers.

Grand jury decisions not to indict the police officers involved in Brown and Garner’s cases sparked nationwide protests.