Shots were fired around 5:20 p.m. as officers served the warrant at an apartment in the city, reports said.
Detective Luca Benedetti was killed in the shooting, according to the San Luis Obispo Police Department.
Benedetti is survived by his wife and two young children, police said. He had served with the San Luis Obispo Police Department since 2012, and before that spent four years with the Atascadero Police Department.
"Our community is heartbroken," Mayor Heidi Harmon said in a statement. "Detective Benedetti loved this city and bravely gave his life so that we could live in peace and safety. Luca’s children have lost their father so we could be safe. We will hold Detective Benedetti and his family in our hearts forever."
The other officer, Detective Steve Orozco, was treated at an area hospital and released Monday evening. Orozco is expected to fully recover, police said.
"As Detective Orozco recuperates at home, we are grateful that his physical wounds will heal, and we recognize that yesterday’s events have changed his life forever," Harmon said.
The officers were part of a group of six serving a search warrant for possible stolen property that police said was related to a series of late-night commercial burglaries over the past week.
After knocking and waiting with no response, the officers opened the door. Inside, a shooter was lying in wait and opened fire, police said.
Police identified the suspected shooter as 37-year-old Edward Zamora Giron.
Officers returned fire and later found Giron dead from a gunshot wound that police said appeared to be self-inflicted, as well as injuries from being hit by the officers' return fire.
Victoria Torres, 21, a neighbor, said she was upstairs in her bedroom when she heard "a very loud knocking" at an apartment across from her.
"I don’t know if it was the police or what," she told the San Luis Obispo Tribune. "I always hear noises here so I didn’t think anything of it until I heard the gunshots."
Torres said she walked downstairs, looked out a window, and saw a man carrying a "big gun" who began shooting at officers from the door of an apartment. She noted that officers were hiding behind their car, the paper reported.
"I was pretty startled and frightened," she said. "I just hid. I looked out the window again when it got quiet. Because I wasn’t sure what happened."
Soon after, Torres said she decided not to watch anymore because "it was too scary," according to the San Luis Obispo Tribune.
Another resident, Monica Rochte, 31, told the paper she heard police banging on an apartment door across the street, saying "We’re going to come in. We know you’re in there."
Rochte said the yelling continued before she heard a bang, and then a single shot. She then heard police yelling "He has a gun!" before a series of 15 to 20 shots rang out.
"This is a tragedy beyond measure for all of those who serve and care about our community," said Derek Johnson, San Luis Obispo City Manager. "Our deepest condolences go out to the family. We are devastated by this loss."
The San Luis Obispo County Sheriff’s Office and district attorney's office are investigating the incident, which Acting Police Chief Brian Amoroso said is standard practice for a case with officer-involved shootings.
"I had the distinct pleasure of working with Luca over the past 9 years," Amoroso said. "He was a dedicated officer, a talented detective, a proud member of the San Luis Obispo Regional SWAT Team, and most importantly, a loving husband and father."