A trench dug up by construction crews working on a sewer project caved in and snapped a 2-inch gas line in the middle of the intersection of San Jose Avenue and Duncan Street around 3 p.m., PG&E spokesman Joe Molica said.
At 4:18 p.m. the flow of gas was stopped, Molica said.
All repairs to the line are expected to be complete around 7 p.m., he said.
In the meantime four customers have no gas service, Molica said.
The hospital, located at 1580 Valencia St., and nearby residents were advised to shelter in place, according to San Francisco fire officials, but those orders were lifted after the leak was capped.
Hospital spokesman Dean Fryer said the leak was on the medical office side of the building, away from the hospital entrance.
He said the air quality of the hospital was monitored throughout the incident and it was unaffected.