The officer was at an intersection late Saturday afternoon when a vehicle believed to be carrying two people and linked to an earlier shooting came alongside, a police statement said.
"According to witnesses, the suspect vehicle pulled up on the left side of the officer's vehicle, pointed a gun out of the passenger window and fired at the officer," police said.
The officer, whose name was not released, was hit by the gunfire and taken to Scripps Mercy Hospital in Hillcrest. Police said he was listed in "extremely critical condition." The statement did not say where the officer was hit.
"As far as we know, it was totally unprovoked," police Capt. Jim Collins told the San Diego Union-Tribune. "He was not attempting to stop the suspect vehicle. He had no idea that was the suspect vehicle."
The gunfire occurred about 5:30 p.m. at University Avenue and 45th Street in the City Heights area on San Diego's east side.
A half hour after the attack, officers tracked down the suspected black Audi to an apartment and saw a suspect carrying a shotgun get in and start to drive away. Police said several squad cars converged on him to make the arrest.
"The suspect grabbed the shotgun and several officers fired their weapons at him," the statement said.
The man, who was not identified, was dead at the scene.
Police believed a second suspect was holed up inside, but later found the unit was empty.
Occupants of the Audi were suspected of being involved in a shooting at an In-N-Out restaurant earlier and 14 miles away in El Cajon.
A gunman with a shotgun shot a man in the face as he sat in his car. Police said he is expected to survive.
Minutes later, an officer who had no knowledge of the restaurant shooting, spotted the Audi speeding and gave chase, but abandoned the pursuit as it speeds of 100 mph, the statement said.