The four-year veteran of the Santa Maria Police Department, whose name has not been released, was manning a DUI checkpoint when other officers approached him and tried to arrest him.
That's when authorities say he put up a physical fight, then he pulled out a gun and shot at the officers.
Several officers came to help the police making the arrest, and one of them shot the suspected officer in the chest once.
The suspect was rushed to the hospital, where he later died.
Detectives had begun investigating the alleged relationship on Thursday night, and minutes before the shooting had confirmed that an "inappropriate" and "very explicit" relationship had been going on, Santa Maria police Chief Danny Macagni said in a statement.
The Associated Press contributed to this story.