A man was shot in the leg while trying to stop a suspected car thief in Brooklyn on Tuesday.

Police said the 28-year-old victim was walking along South Second Street near Hewes Street in Williamsburg just before 4 p.m. when he noticed a man carrying tools trying to gain entry to a vehicle.

The victim tried to stop the man and hold him there until officers could arrive, according to police. That’s when the man pulled out a gun and shot the victim in the leg, police said.

The victim was taken to Bellevue Hospital Center in stable condition, according to police.

Officers arrested the man, identified as Hector Bello, 44, at the scene, police said.

Bello, of Brooklyn, is charged with assault and criminal possession of a weapon, police said.