A huge blackout probably caused by a fire at a PG&E substation swept through San Francisco on Friday, bringing everyday life to a virtual standstill as homes and businesses and courtrooms went dark, traffic lights stopped working, BART and Muni service slowed, and all the cable cars shut down.

The power failure, which at its height affected 88,000 customers, struck just after 9 a.m. and extended through the Tenderloin and Chinatown, up Nob Hill, and into the Marina and the Presidio. But as the evening commute began at 4 p.m., there was finally good news: Power had been restored to all but about 3,000 customers. An hour later, everyone had power.

While no major injuries were reported, the ordeal meant everything from lost business at shuttered shops in Union Square to minor shakeups for people briefly trapped by darkness in the bowels of downtown skyscrapers.

Firefighters responded to more than 100 calls for service in the Financial District and beyond, including 20 elevators with people stuck inside. Everywhere, sirens blared as engines maneuvered along streets jammed with traffic. Hospitals, though, were operating on backup power, with most surgeries and other procedures continuing.

“Big Lesson: backup generators,” Mayor Ed Lee said at an afternoon news conference. “It worked.”

As people waited for power to come back, they gathered on sidewalks and in cafes that were lucky enough to have generators, sharing stories about the blackout.

Andrew Henry was in his 20th floor hotel room at the JW Marriott hotel in Union Square with his two sons — Isaac, 11, and Elliott, 8 — when the lights went out. The hotel’s backup generator failed, so the vacationers from Vancouver, British Columbia, took the stairs down, with glow sticks lighting the way.

After making it to the street, they decided to wander around Chinatown.

“We had two good days with weather and power,” Henry said, “and another with good weather and no power.”

Pacific Gas and Electric Co. traced the problem to the failure of a circuit breaker that ignited insulation and started a fire at a substation at Larkin and Eddy streets, just north of City Hall. The equipment was slated for a $100 million overhaul that was under way, said Barry Anderson, a vice president at the utility.

The failure was “from old equipment,” he said. “The equipment failed before we could get to the upgrade.”

Firefighters reported that the substation blaze was extinguished at 11 a.m. All PG&E employees who work at the site were reported safe.

Amid the blackout, downtown streets became clogged as drivers stewed and honked at each other. More than 100 parking control officers as well as police officers were deployed to control the flow through intersections as about 300 traffic lights — about a quarter of those across the city — went dark.

BART’s Montgomery Station was closed for more than two hours, with trains running through the station without stopping, before the agency reopened it by using generators. Still, power to elevators and escalators couldn’t be immediately restored.

All of the city’s cable cars were down, disappointing tourists on a busy Friday, as were several Muni bus lines that typically run on electricity from overhead wires, including the 30-Stockton, 45-Union/Stockton, 22-Fillmore and 24-Divisadero lines. Shuttles were put in place to provide service, the Municipal Transportation Agency reported.

Muni trains were still running both underground and above ground, though delays were reported because of the extensive problems with traffic lights. The subway stop at Montgomery Street was closed, with Muni trains — like BART trains — running through without stopping.

Nineteen schools in San Francisco were struck by the power failure, including Spring Valley Science School, Sutro Elementary, Civic Center Secondary School, Alamo Elementary, Galileo Academy of Science and Technology, and Cobb Elementary.

“Student and staff safety is our priority,” said spokeswoman Gentle Blythe. “All schools remain open and are adjusting their instruction as needed.”

The Phillip Burton Federal Building and U.S. Courthouse at 450 Golden Gate Ave. was among the many buildings closed by the blackout.

Daisy Prado, a 23-year-old South Bay resident, said she was sitting at her desk on the 14th floor of an office building on the 200 block of Montgomery Street in the Financial District when the power suddenly dropped out. She looked out the window and saw the buildings across the street go dark.

“They told us on an intercom to just stay calm,” Prado said soon after the blackout. “People are hanging out the side of their buildings waiting to see what’s going to happen.”

Prado said she left work, looking for a coffee shop with power and Wi-Fi.

Aaron Trzesniewski was in a cable car near Sutter and Powell streets when the electricity cut out.

“It’s huge,” Trzesniewski said. “All the retailers are down, all the businesses, Starbucks, everybody.”

All around Union Square, the lights were out in the boutiques and restaurants, and rows of shuttered businesses extended into the Tenderloin and Chinatown. Workers stood outside waiting, or in some cases they stood inside with the doors closed.

“The money is stuck in the drawer,” Italo Amaral, an employee with the Sutter Street cafe Bread and Cocoa, said after his cash register and credit card machine lost power. “We’ll see what’s going to happen.”

Many hotels and some stores, including Neiman Marcus on Stockton Street, continued on as usual, thanks to generators.

But some businesses gave up and closed for the day. A lot of people just milled about, drinking coffee or staring at their phones.

Chronicle staff writers David Baker, Kurtis Alexander and Rachel Swan contributed to this report.

Sarah Ravani, Jill Tucker and Hamed Aleaziz are San Francisco Chronicle staff writers. Email: sravani@sfchronicle.com, jtucker@sfchronicle.com, haleaziz@sfchronicle.com Twitter: @SarRavani, @jilltucker, @haleaziz