LOS ANGELES — All 31 construction workers who were far inside a huge industrial tunnel when part of it collapsed in Los Angeles made it to safety Wednesday evening, an outcome officials called a blessing after they initially feared much worse.

The cave-in apparently happened between the tunnel boring machine, 5 miles in from the only entrance, and the construction crew working 6 miles in, said Michael Chee, spokesperson for the Los Angeles County Sanitation Districts, which is in charge of the nearly $700 million project. The workers were about 400 feet underground.

The tunnel is being constructed almost entirely underneath public right-of-way. The structure is 18 feet wide and will be 7 miles long to carry treated wastewater from across Los Angeles County to the Pacific Ocean.

Firefighters said workers had to climb over 12 to 15 feet of fallen dirt and debris to reach the tunnel boring machine and then were transported by vehicle back to the opening. Some people had to be pulled out.

Fire Department Chief Ronnie Villanueva said the workers had to make it through the most treacherous part themselves before rescuers could assist them the rest of the way out.

Aerial footage showed workers being brought out of the tunnel in a yellow cage hoisted up by a crane. None had major injuries, authorities said.

The workers were operating the boring machine when the collapse occurred, said Robert Ferrante, chief engineer and general manager for the sanitation districts.

“A section that they have already built had squeezing ground and had a collapse, a partial collapse,” he told reporters.

Arally Orozco said she was at church when her phone started buzzing with calls and her son texted her the news of the tunnel where her three brothers worked.

“It was sad and scary,” she said in Spanish. “We feared the worst.”

After an hour, she managed to get through to one brother who told her they had to squeeze through a tight space to get out.

“My brother was crying,” she said. “He told me he thought he was going to die underground.”

The collapse happened under the Wilmington neighborhood, a heavily industrial area filled with oil refineries just north of the Port of Los Angeles.

LA City Councilmember Tim McOsker praised the workers for keeping cool heads.

“This is a highly technical, difficult project. And they knew exactly what to do. They knew how to secure themselves,” he said.

Mayor Karen Bass said at a news conference that she met with some of the workers.

“I know when we raced down here I was so concerned that we were going to find tragedy. Instead, what we found was victory,” Bass said. “All of the men that were in that tunnel, rescued, up, safe.”

The cause is under investigation, Chee said. Work will not resume until they can figure out what happened and determine that it’s safe to proceed, authorities said.