A man was being treated at Pittsburgh’s Allegheny General Hospital after emergency crews freed him from a collapsed trench early Friday in Charleroi.

Rescue workers freed the man at about 1:30 a.m. after about five hours of effort involving emergency organizations from multiple counties, according to TribLive news partner WTAE.

Charleroi fire Chief Robert Whiten Jr. told WTAE the man had a possible broken ankle but was in “pretty good spirits.”

“It was just a total, like, a well-oiled machine working in there,” Whiten said of the rescue. “And it paid off. The individual walked out, didn’t have to be carried out.”

Whiten estimated the trench was about 15 feet deep. WTAE reported the trench was located outside a home in the 800 block of McKean Avenue.

Whiten said the man was talking and was being treated with an IV while the rescue was underway.

An air compressor truck was used to loosen dirt surrounding the man and a vacuum truck sucked it out of the trench, he said.

He said a secondary collapse occurred but shoring stopped it from hitting the man.

Whiten said rescue crews worked around a mini excavator in the trench that was secured with the help of a towing company.

He wasn’t sure of the extent of the work that had been underway at the site but said it had been going on for a few weeks.

Columbia Gas told WTAE that work was not being done to a gas line there. It was believed to be a sewer line project, a spokesperson said.

The Occupational Safety and Health Administration will investigate the incident, Whiten said.