Cops on routine patrol were targeted by a gun-toting thug who fired at them early Sunday in Queens, police said.

A plainclothes sergeant and a police officer parked their unmarked car across the street from the Redfern Houses in Far Rockaway on Redfern Avenue near Hassock Street at 1:45 a.m., according to cops.

They had planned to access the rooftop of the NYCHA building to monitor the activity of six men who were standing in front of 14-30 Redfern Ave., cops said.

As they approached the entrance, one of the suspects brandished a pistol and fired three shots at police, authorities said. The cops did not return fire, but took cover and called for assistance.

The sergeant was treated at Long Island Jewish Medical Center for tinnitus, and the police officer was treated at the same hospital for back spasms and bruising to the knee, officials said.

The six were captured on video surveillance fleeing the location.

Anyone with information is being urged to call the NYPD’s Crime Stoppers hotline at 800-577-TIPS. The public can also text tips to 274637 (CRIMES) then enter TIP577.