The shooting started just after midnight on Elton Avenue in the Melrose section.
Police say they initially observed two men spray painting graffiti and made a stop at 153rd and Third Avenue.
The men then got in the car and tried to flee when officers pulled them over and they took off on foot, authorities said.
Officers gave chase and caught up with one of the men when there was a struggle and they say the man pulled a semi-automatic hand gun on the officers and began firing. After a brief foot chase, one officer was able to grab one of the subjects. As the officer struggled with the man in an attempt to arrest him, the subject pulled out a semiautomatic handgun and fired at least three rounds at the officers, said NYPD Chief Terry Monahan.