The standoff ended at about 6:50 a.m. when police officers went into the second-story apartment in the Skyline area of southeast San Diego and found a man and woman dead, Lt. Andra Brown said.
At least one of them was believed to have opened fire on officers the night before, she said, adding that it was not immediately clear whether the two committed suicide or died during the shootout. They were not immediately identified.
Three other people in the apartment were detained earlier and more than 50 people were evacuated from surrounding apartments during the standoff, she said.
The confrontation began at about 10:45 p.m. Wednesday when federal probation officers and U.S. marshals went to the apartment to check on a man who was on probation for assault with a deadly weapon, Brown said.
Acting Assistant Police Chief Jim Collins said someone inside opened the door, then slammed it in their faces.
The officers kicked in the door and took a man into custody, then called in San Diego police to help search for other people inside the apartment.
The apartment complex manager told the San Diego Union-Tribune that she heard police kick open a door inside and there was a burst of gunfire.
A tenant, Ryan Davis, estimated there were six to 12 shots fired from what sounded like handguns and a shotgun.
"There was a hail of bullets," Brown said, but he declined to provide an estimate.
Three officers, including the fatally wounded officer, returned fire, police said.
Two officers fled the apartment, then went back inside to retrieve their wounded comrade, Brown said. He died at about 3 a.m. Thursday at a hospital. His name was not immediately released.
A police dog named Monty also was wounded in the shooting but is expected to survive, Brown said.
Dozens of San Diego police, county sheriff's deputies and federal officers responded to the officers' call for help and a special weapons team cordoned off the apartment.
Scores of residents, some barefoot or in pajamas, were herded out of the apartment, the San Diego Union-Tribune said.
Two other people were arrested hours later after the SWAT team fired a flash-bang grenade inside.
Hours later, the last two bodies were discovered.
Collins said the first man taken into custody lived in the apartment. Residents of the apartment complex told the Union-Tribune that the man lived with his mother, and had a brother who was often there with his girlfriend.