The leak was reported at 11:05 p.m. Monday at 1831 33rd Ave.
San Francisco fire Lt. Mindy Talmadge said firefighters arrived at the scene but were unable to shut off the gas because a valve was rusted shut.
PG&E crews got there at about 11:15 p.m. and stopped the flow of gas just before 1 a.m., utility spokesman J.D. Guidi said.
Four homes had been evacuated, and the residents of three of those homes were let back in when the leak was stopped, he said.
Repairs were completed at 3:50 a.m. and residents of the fourth home have since been allowed to return.