(KTLA) – Firefighters in California rescued a bear that got trapped in a back lot at Six Flags Magic Mountain 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.

A Fire Department crew arrived at the scene, along with officers from the California Department of Fish and Wildlife and animal control.

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

Members of the L.A. County Fire Department work to rescue a bear that became trapped at Six Flags Magic Mountain. (Los Angeles County Fire Department)

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

Get daily news, weather, breaking news, and sports alerts straight to your inbox! Sign up for the abc27 newsletters here. 

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 the California Department of Fish and Wildlife.