The fire broke out in an apartment building on Pine Street near Laguna Street around 1:40 p.m.
A resident flagged down the police officer as he was driving to another call. That person told the officer about a woman who was trapped inside her home.
"We don't get trained in how to go into a burning building, but we're trained to protect life and property and that's exactly what he did today and he's truly a hero," San Francisco Police Lt. Jenn Jackson said.
The police officer needed treatment after suffering smoke inhalation. The fire also sent two other people to the hospital with minor injuries.