As police chased him on foot, a Dorchester man allegedly pointed a military-style rifle at officers, prompting one of them to open fire and shoot the man in the leg.

That was the culmination of a car chase through Dorchester late Saturday night in which four gang members were arrested, police said.

Inside the PT Cruiser in which the men fled, police said they found a .40 caliber handgun, 40 rounds of ammunition and masks.

“This is a clear case of a group of gang members who were on a mission to carry out a senseless act of violence,” Police Commissioner Ed Davis said in a statement. He added that the officers prevented a homicide by attempting to stop the car and then pursuing the suspects.

Marvin Vega, 21, was being treated at Boston Medical Center. He and the three other men are expected to be arraigned today.