SAN FRANCISCO (AP) -- Fire investigators on Wednesday were looking into whether welding work was to blame for a massive blaze that barreled through an apartment building construction site, threatening nearby structures and prompting evacuations as firefighters worked to prevent its spread through a San Francisco neighborhood.
City officials said a catastrophe was narrowly avoided in an up-and-coming area near AT&T Park, home of the Giants.
"I think we're very lucky that the fire didn't jump anymore," Mayor Ed Lee said.
The exact cause of the blaze -- one of the largest in the city in recent years -- was under investigation. Fire officials were looking into preliminary reports that workers at the block-long site were doing torch work shortly before the fire was reported around 5 p.m. Tuesday, Fire Chief Joanne Hayes-White said.
"It's too early to determine a cause at this point," Fire Department Battalion Chief Kirk Richardson said. "Our arson investigators still have a lot of material they have to look at."
Two firefighters suffered minor injuries. One of them, Tom Murphy, suffered burns while battling the fire from above but didn't realize he was injured for hours, said firefighter Stephen Maguire, whose crew was among the first to arrive.
The five-alarm fire created a plume of black smoke that was visible for miles and led to the evacuation of nearby buildings as about 150 firefighters were called to contain it. A wall of the burning building collapsed about an hour after the fire began.
Firefighters had to take a defensive stance because the building was leaning in some areas, Maguire said.
The blaze cracked windows at Strata at Mission Bay, an apartment building across the street, and sent an ember onto the roof of a University of California, San Francisco building.
Flames briefly spread to scaffolding at another building under construction, Maguire said.
The fire was fueled by wooden frames and other materials at the site, Hayes-White said. Because it was under construction, the building had no fire-suppression systems.
"Our objective last night, which we were able to achieve, was to contain (the fire) to the building of origin," she said.
Fire officials did not yet have a damage estimate but said the entire six-story building was a loss.
By late afternoon Wednesday, construction crews were using an excavator to tear down the structure on one end while firefighters on the other end doused hotspots.
Firefighters will likely remain on the scene throughout the night to make sure the fire doesn't rekindle, Richardson said.
Meanwhile, some nearby residents were allowed back into their homes Wednesday evening except for those living in the Strata at Mission Bay.
Exterior sprinklers on the building have to be replaced and the fire protection system restored before Strata residents can be allowed back in, fire Deputy Chief of Operations Mark Gonzales said. About 30 Strata units suffered damage, fire officials said.
Earlier Wednesday, Eli Brill and his wife Justyn Bellsey, both 31, temporarily returned to their apartment at Strata to retrieve belongings. Firefighters had helped them retrieve their dog the previous night.
"It was really scary," Bellsey said. "I'm just relieved that we were able to get in."
The burned building was part of a residential development project with 172 units, according to BRE Properties, the building's owner.
It was going up in a former industrial area that became a redevelopment district in the 1990s and has since attracted a mix of high-end residential housing and retail businesses.
A new University of California, San Francisco hospital is also being built.
Associated Press writer Channing Joseph contributed to this report.