The man, who has not been identified, was allegedly assaulted by Anthony Jones, 53, at about 10:50 a.m. Friday in the 500 block of Page Street, police said.
Police said the man stabbed Jones, a San Francisco resident, after Jones attacked him with a shovel.
Both men were taken to a hospital, where Jones later died.
Police sent the case to the district attorney's office.
District attorney spokesman Seth Steward said today that the man who stabbed Jones will not be prosecuted for the death.
"If it happened as a result of someone defending themselves, then legally they don't have to be charged," police Lt. Troy Dangerfield said.