A bear has attacked and injured a 10-year-old boy who was hiking with his family in a US national park.

The female grizzly bear is believed to have been foraging with a cub when it encountered the family.

The boy ran away from the bear when it charged out of vegetation towards the family but the bear chased and knocked him to the ground.

The incident occurred at Yellowstone National Park, which spans the US states of Wyoming, Montana, and Idaho.

The boy's parents used pepper spray to fight off the bear, who is thought to have been defending its cub.

The 10-year-old, who was visiting with his family from Washington state, had "an injured wrist, puncture wounds to the back and wounds around the buttocks" as a result of the incident, the US National Park Service said in a statement.

"This incident could have been more serious. We applaud the family for travelling in a group, carrying bear spray, and knowing how to effectively use it," Yellowstone National Park Deputy Superintendent Pat Kenney said.

Park rangers do not intend to search for the bear since this incident was a surprise encounter.

Prior to the incident, there had not been a reported bear attack in the Yellowstone park since 2015.