DOVER-FOXCROFT, Maine — A three-unit apartment building and attached barn in Dover-Foxcroft were destroyed in a blaze Tuesday, and the town’s fire chief credited nearby contractors with saving the lives of a few residents.

Firefighters were sent to the property on Cherry Street at 10:43 a.m. Tuesday. The fire was accidental and began after a bucket with cigarette butts on the porch caught fire, which spread to the residence and into the second floor, Dover-Foxcroft Fire Chief Brian Gaudet said.

A mother and son living on the first floor were not home when the fire started, he said. A woman and her dog on the second floor “made it out in the nick of time,” said Benjamin Fagan, a lieutenant at the department.

Crews had to pull a man out of a first-floor window, and it was a contractor working next door who alerted firefighters to the resident trapped inside. They also helped the woman on the second floor.

“If it weren’t for the contractors working next door, I strongly feel that the second-floor occupant may not have been able to escape,” Gaudet said. “Their quick action and thinking, I believe, saved the woman.”

Two firefighters were treated for minor injuries at the scene, the chief said. One contractor received minor burns while trying to help the residents inside.

The main part of the building is still standing, but an excavator tore down the rear portion of the building because it was too dangerous for crews to go inside, Gaudet said. Within about 15 minutes of firefighters arriving, the barn collapsed.

“This was a fast-moving fire because of the age of the building,” Fagan said, noting crews knocked down the fire quickly, but then it would come back and spread.

The roof system, which had multiple layers and cedar shingles, made it particularly challenging, he said.

Firefighters battled the blaze for more than six hours, Gaudet said. He requested help from departments in Piscataquis and Penobscot counties because of the intensity of the fire, and 11 agencies provided aid.

Residents of the building are mostly coordinating with family and friends to find places to stay, he said. The American Red Cross is also available to provide services.