Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A man hiking in a national park in Utah got stuck in quicksand and stayed trapped until late that night when rangers were able to reach and free him.

The hiker, Ryan Osmun, then remained with rescuers in the park overnight in frigid, snowy weather until visibility was high enough the next afternoon to airlift him to an awaiting ambulance.

Man pulled from quicksand in Zion during two-day rescue. Alyssa Baltrus / NPS

The 34-year-old hiker, who is from Arizona, was walking a trail Saturday at Zion National Park with a female friend when his leg became stuck in quicksand along the Left Fork of the North Creek, the National Park Service said Monday.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

“His leg was buried up to his knee and he was unable to free himself,” agency officials said in a statement. "He and his companion tried to free his leg and were unsuccessful."

The woman, Jessika McNeill, left the Osmun with warm gear and clothes, and then hiked three hours until she could get cell phone service and called 911.

It took a park search-and-rescue team another several hours before they were able to locate the hiker, the National Park Service said.

When rangers were finally able to get to him, he was suffering from exposure and hypothermia due to the extremely cold weather, in addition to injuries.

Ryan Osmun takes a selfie with his girlfriend, Jessika McNeill, at Zion National Park on Feb 16. Ryan Osmun

"Late into the night, Rangers were able to free the male from the quicksand and began efforts to rewarm him and treat his leg," the park service said.

Due to deteriorating weather conditions, rescuers decided it was safest to spend the night in the park with the injured hiker. The man was airlifted out of the park and then taken to the hospital the following afternoon, park officials said.

A spokesperson for the park service told NBC News that quicksand usually isn't an issue at Zion National Park.

"It does happen if conditions are right," she said. "Quicksand can form in saturated loose sand with standing water. If it is the right saturation point, and you step into it and the water cannot escape, it creates a liquified soil that cannot support weight. We have been unusually wet here this winter. The weather was most likely a contributing factor."