Madera police said the officer attempted to make a traffic stop on Howard Road at Schnoor Avenue when the suspect driving a Mazda SUV sped off around 4:30 a.m.
As the suspect weaved through the neighborhood, a passenger in the Mazda reached out the window and shot at the police cruiser, shattering a window and narrowly missing the officer and a civilian passenger, police said.
"I heard a bunch of shots like, 'pop, pop, pop,'" one witness said. "I got kind of scared because it's not normal for this area."
Damage from the gunfire forced the officer to pull off and police said the Mazda was found abandoned down the street along with a pistol.
The officer was not hurt. The passenger was hit by broken glass, but will be OK. The cruiser was hit three times.
Police said the officer had only been with the department for two weeks when the shooting happened.
"It is the stark reality of law enforcement," Madera Police Department Lt. Gino Chiaramonte said. "He kept it under control, still had cognitive process and at the same time still thought about his passenger and paid attention to what the suspect was doing."
Authorities are searching for the suspects involved.