Sheriff's deputies were performing a welfare check at a triplex apartment complex on North Fifth Street near Crescent Avenue in unincorporated Castro Valley around noon because a friend of the woman who died requested one, Sgt. J.D. Nelson said.
Sheriff's deputies saw the woman's car in the driveway, but no one answered when they knocked and rang the doorbell.
The sheriff's sergeant and deputy used a ladder to get inside through the second floor, and when they climbed it they saw two people lying on the ground, Nelson said.
The woman was dead and the man got up and tried to attack them with a knife, he said.
The two shot and killed him.
Nelson did not know the relationship between the man and the woman.
He said deputies have checked on the woman's welfare in the past because of domestic disputes, but he did not know if this man was involved in those incidents.
The deputy and sergeant were not injured.