Firefighters rescued a bear that got trapped at a Six Flags Magic Mountain back lot last week, authorities said.

The bear wandered onto the lot at the Valencia amusement park on May 5 and somehow got stuck between two cargo trailers, according to the Los Angeles County Fire Department.

California Fish and Wildlife first got a call from Six Flags security reporting that the bear had wandered onto the facility around 2 a.m.

As people started arriving later in the morning, the bear likely got spooked by the commotion and wound up getting stuck between two large containers, California Fish and Wildlife specialist Jessica West told KTLA.

“There was concern, given that the park was open to the public, so we did respond,” West said.

A Fire Department crew and animal control personnel responded to the scene, along with California Fish and Wildlife officers.

“They worked diligently and patiently for the next several hours to free the bear,” the Fire Department said in a news release.

After the bear was sedated, firefighters used equipment to move one of the trailers to get to the animal.

Images shared by the Fire Department showed the sedated bear being prepared for transportation.

Fire officials said the animal was safely relocated by personnel from Fish and Wildlife.

West said it’s not very common to see bears in the area and it was her first time hearing about one at Six Flags.

“For a bear to end up at Six Flags, that was a new one for me,” she said.

“Six Flags Magic Mountain was probably quite the attractant, considering the amount of food and smells for that bear,” West added.

She advised residents who come face-to-face with a bear to give the animal space, not turn their back to it, speak in a low but firm voice and then just back out of the situation.

“Bears are unconfrontational, they’re really just interested in food that we’ve put out on the landscape, essentially,” she said. “So most of the time,  these animals just they’re more afraid of us than we are of them.”