He was sleep-deprived and nearly out of ammunition, alone in the wilderness of Alaska. Well, not really alone.

For several nights in a row, the man had fended off the tenacious advances of a grizzly bear that had attacked him a few days earlier at a mining camp some 40 miles outside Nome.

There was no way to phone for help. But then help found him.

En route to a mission Friday, the crew of a Coast Guard helicopter saw the man waving both hands in the air, a widely recognized distress signal, the helicopter's pilot said. On the tin roof of a shack, SOS and "help me" had been scrawled. The shack's door had been ripped off.

The crew took the man to Nome to be treated for bruises to his torso and a leg injury that was not life-threatening, according to the Coast Guard. So ended a weeklong ordeal that could pass as a sequel to "The Revenant," in which Leonardo DiCaprio was mauled by a computer-generated grizzly bear.

"At some point, a bear had dragged him down to the river," Lt. Cmdr. Jared Carbajal, one of the pilots of the Coast Guard helicopter, said in an interview Wednesday. "He had a pistol. He said that the bear kept coming back every night and he hadn't slept in a few days."

The Coast Guard did not identify the man, who rescuers said was in his late 50s or early 60s and had been staying in the shack since July 12 on the small mining claim.

Carbajal said that the Coast Guard MH-60 Jayhawk helicopter had changed its course by about a mile to avoid some clouds when something caught the eye of his co-pilot.

"He said, 'Hey there's a guy down there and he's waving at us,' " Carbajal said. "I said, 'Is he waving with one hand or two hands?' "

The answer: two hands.

"I said well, that's usually a sign of distress," the pilot recalled telling the helicopter's three other crew members.

Lt. j.g. A.J. Hammac, the 35-year-old co-pilot, said in an interview Wednesday that he saw the man stumble out of his shack. It was a curious sight for him. Hammac is based on Cape Cod in Massachusetts and is spending two weeks in Alaska for the Coast Guard.

"We don't really come across people in the middle of nowhere," Hammac said. "He was kind of struggling. When we came around, he was on his hands and knees waving a white flag."

Hammac said the man's leg was taped.

"He definitely looked like he had been out there for a while," he said.

According to a 2019 report by Alaskan health officials, 68 people in the state were hospitalized for injuries sustained in 66 bear attacks from 2000 to 2017. Ten people died.

Petty Officer 1st Class Ali Blackburn, a spokeswoman for the Coast Guard in Alaska, said Wednesday that it was unusual to have several encounters with the same bear. She said the man's situation had become increasingly dire.

"He only had two rounds left," she said of his ammunition.