Updated

A veteran, second-generation police officer was in critical condition in a medically induced coma after being wounded in a shootout where the rookie officer he was training shot and killed a gunman, authorities said.

The wounded officer, 31-year-old Gabriel Garcia, whose father is a captain in his department, underwent surgery for at least two bullet wounds from the protracted gun battle, San Bernardino police chief Jarrod Burguan said Friday.

Garcia and his partner — a trainee on the job for just two months — stopped to talk to a group of people standing outside a home on a cul de sac when one of them pulled a gun and immediately opened fire, Burguan said.

He was shot, but his partner managed to shoot the gunman in the long gun fight that followed, the chief said.

The officer in training was not hit during the gunfire. Given his level of experience, his response was exceptional, Burguan said.

"He did a pretty remarkable job," the chief said.

The shooter, identified by police as Alex Alvarado, 38, died at a hospital.

Garcia was initially said to be in grave condition, but after he made it through surgery police expressed new hope for his survival, and officers, family and friends gathered at the hospital for a vigil Friday night.

"The next three to five days are absolutely critical in terms of Gabe's long-term prognosis," Burguan said.

Garcia is a highly commended, six-year veteran of the department who has spent much of his career on patrol duty and some time on a graffiti task force, Burguan said.

"He is exemplary in every sense of the word," the chief said.

Five people were detained and questioned by detectives. It was unclear why the officers made contact with the group.

Jonathan Contreras, 20, of San Bernardino was arrested on suspicion of possession of an assault rifle and possession of a sawed-off rifle, officials said. While Alvarado fired the weapons, they were in the possession of Contreras, the chief said.

Another man, 24-year-old Orlando Cruz, was arrested in connection with outstanding traffic warrants. Two women, 18 and 19, and a 30-year-old man were also questioned.

"We don't know what their level of involvement is," Burguan said.