CANAAN — After six bone-chilling hours trapped inside a Hudson Valley cave last weekend, a downstate man was brought to safety thanks to a daring rescue by state forest rangers.

The unidentified Brooklyn man was exploring Merlin’s Cave with friends Sunday evening when his pelvis and ribcage became wedged in a tight crevice about 400 feet from the cave’s entrance, according to a release from the state Department of Environmental Conservation.

Some members of the group exited the cave to call 911, while three others stayed behind with the trapped man, Forest Ranger Lt. John Gullen said in a recorded video released by the DEC.

After Gullen and other volunteers from the National Cave Rescue Commission entered the cave shortly after 9 p.m., they quickly realized the severity of the situation. At the time, the cave’s temperature was about 50 degrees with nearly 100% humidity. The man who was trapped and his three friends had been in the cave for many hours and were “all hypothermic,” Gullen said.

Because the man was surrounded by rock on all sides, rescuers could not place a foam pad between him and the cave wall to help warm him.

The three friends who remained with the man had been trying to free him by chipping away at the rock with a hammer, Gullen said. Once they squeezed past rescuers and made their way out of the cave, Gullen positioned himself behind the trapped man. But he soon encountered difficulty.

“His full body was stuck in a crevice that was basically designed (in) the exact shape of him,” Gullen said.

Time was also a factor. Gullen said the rescuers would have had to take “more aggressive measures to get him warm if we couldn’t get him out soon.”

After about two hours of attempting to free the man using manual techniques, rescuers determined that they needed a hammer drill, a more powerful tool designed for heavy-duty drilling into hard materials. Two members of the rescue team left to retrieve one while Gullen remained with the trapped man.

Once the drill arrived 90 minutes later, rescuers spent about 20 minutes carefully boring into the rock, just inches from the man’s head and back. The effort worked, and the man was freed.

These types of rescues can sometimes take multiple days, Gullen said.

“To get him free after just 20 minutes of drilling, it felt great,” he said. “Once we were able to get to a point where we could high-five, we were high-fiving.”

Despite the ordeal, the man remained relatively calm and in good spirits, Gullen said. Aside from needing warm fluids and food, he was uninjured.

“He was stuck for a total of six hours, unable to move basically in any direction,” he said. “For most people, that’s like their worst nightmare.”