A Brooklyn man was critically wounded by police fire when he brazenly stole a gun from a sergeant after hopping into an unmarked cop car early Sunday, law-enforcement sources said.

The 25-year-old suspect got into the backseat of the car while a Detective Bureau Division officer and a sergeant were stopped at a red light in East Flatbush at 12:45 a.m., cops said.

It was unclear if the man knew he had gone into the back of an unmarked police car, but he began a fierce struggle with the sergeant, who was seated in the front passenger seat.

The sergeant tried to shoot him and fired off a round, but the man boldly grabbed her gun and took off running away from the car on Avenue D and Nostrand Avenue, cops said.

Three other cops quickly surrounded him and ordered him to drop the gun– a uniformed cop on foot patrol who rushed to the scene, and two others from a nearby patrol car.

Instead, the suspect opened fire on the cops who returned with a hail of bullets, striking the suspect at least three times in his torso and lower leg.

None of the officers were hurt during the gunfire.

The suspect was taken to Kings County Hospital, where he was in critical condition but expected to survive, according to authorities.

His name has not yet been released, since charges are pending.