A man hiking by himself in in Montana's Glacier National Park kept hiking the trail until he found help after he had been attacked by a grizzly bear, the National Park Service said.

The 50-year-old man was hiking on the trail from Many Glacier to Piegan Pass alone Friday when he rounded a bend and encountered a female grizzly and another bear, the agency said in a statement.

The grizzly attacked the hiker, biting his left thigh and his forearm before hoisting him by the foot and shaking him, the park service said. The bear then dropped him and fled.

Initial reports indicated the hiker was making noise and carrying bear spray but was unable to use it before the attack.

After the attack, the man continued to hike and eventually came upon a ranger leading a hike. The ranger immediately notified dispatch, while the hiker continued to the Many Glacier Ranger Station and was treated for his injured, according to the statement.

He was reported in stable condition after he was transported to the Blackfeet Community Hospital in Browning, Montana. He was treated for his wounds and released.

Hospital officials said the man was "very lucky."

The trail from Piegan Pass to Feather Plum Falls was closed Friday while rangers investigated the incident.