San Diego officers were assisting the U.S. Marshal's Service and probation officers in a check on an assault with a deadly weapon suspect and were inside the apartment when the suspect opened fire at 10:45 p.m. Wednesday, Lt. Andra Brown said.
Three officers, including the fatally wounded officer, returned fire and backed out of the apartment in the Paradise Hills area of southeast San Diego.
"There was a hail of bullets," Brown said when asked to estimate the number of gunshots.
Officers carried the wounded officer out of the building and he died at a hospital.
"There was heroic action by the officers," the lieutenant said.
The type of weapon wasn't immediately known. The name of the officer is being withheld. Brown would only say he was a veteran officer with more than 15 years on the force.
A police dog was also wounded.
At least two people inside the apartment with the gunman emerged later. They weren't hurt.
The gunman remained barricaded inside the apartment with a SWAT surrounding the complex. Nearby apartments were evacuated, displacing at least 50 people.
Brown said at 5:15 a.m. Thursday that the SWAT team was preparing "a tactical entry."