A San Bernardino police officer was in critical condition "fighting for his life" on Friday after being shot by a man who was subsequently killed by the officer's trainee partner in a gun battle, officials said.

Gabriel Garcia, 31, the son of a San Bernardino police captain, was out of emergency surgery Friday morning, with his family at his side, San Bernardino Police Chief Jarrod Burguan said.

"Not a lot of positive news on his prognosis," Burguan said.

Garcia was described as "exemplary in every sense of the word." Garcia, who has six years on the force, was recognized for his work with the San Bernardino Graffiti Task Force.

"Gabe is an outstanding officer, a great team member and a great man," Burguan said. "He has always displayed extreme professionalism and a great attitude towards his job, earning the utmost respect from fellow officers and the department as a whole."

Garcia was hit by bullets after 2 a.m. as he and his trainee partner pulled up to a group of about six people standing near a home in the 1900 block of North Garner Street.

The group had been at a nightclub and had been drinking alcohol, police said.

"Almost immediately, there were gunshots that rang out, and the first officer went down," police said in a statement.

The unidentified trainee officer, who had only been on patrol for about two months, got into a "protracted" gunbattle, the Police Chief said.

The suspected gunman, identified as Alex Alvarado, 38, was killed.

School police officers were the first ones to respond, but did not fire their weapons, police said.

Garcia was rushed to a hospital where he underwent emergency surgery. Garcia suffered two gunshot wounds to the upper body.

Burguan described Garcia as a very good police officer, who is well-respected by his peers and his supervisors.

"Has a great reputation for working hard and does very good police work," Jarrod said.

Police took five people into custody for questioning, despite earlier reports that six people were in custody.

Jonathan Contreras, 20, of San Bernardino, was arrested on suspicion of possession of an assault rifle and a sawed-off rifle, police said.

Orlando Cruz, 24, was arrested on unrelated traffic warrants. A third man was arrested on suspicion of possession of methamphetamine.

Two women were questioned and released.

Police said they recovered from the scene a revolver and an assault rifle with high-capacity magazines attached to it.

It is unclear which weapon was used to wound Garcia.

It is also unclear whether Garcia had fired any shots before being struck by gunfire.

It appeared there were at least 65 shell casings at the scene.

"We obviously had a pretty extensive scene. There were a lot of rounds at the scene," Burguan said.

Kevin LaBeach and Andrew Lopez contributed to this report.