Four people were injured on the Ninja ride at Six Flags Magic Mountain, the Los Angeles County Fire Department said. Two of the four were taken to a hospital as a precautionary measure.
The front part of the roller coaster detached from the track and hanged about a 45-degree angle, pointing to the ground.
The car was about 20 feet in the air, Los Angeles Fire Department supervisor Ed Pittmann told CNN affiliate KTLA.
Rescue workers climbed atop the track and used a thick rope to tie the front of the car to the track above.
By late Monday night, all 22 passengers had been rescued.
The derailment happened after a tree branch fell on the track, obstructing the train, Six Flags Magic Mountain spokeswoman Sue Carpenter said.
Six Flags describes the Ninja ride as a “stealth assassin” on its website.
“The black belt of roller coasters whips you into submission,” the site says.
Passengers ride the swinging coaster suspended from the track instead of riding on top of the track.
The derailment is the latest in a series of high-profile roller coaster accidents in recent years.
Last July, Six Flags Over Texas in Arlington shut down its Texas Giant roller coaster after a woman was thrown from her seat and plunged to her death.
Between 1990 and 2010, more than 92,000 children were injured in amusement ride-related incidents, according to a study by the Center for Injury Research and Policy at Nationwide Children’s Hospital in Ohio. That’s an average of more than 4,000 injuries per year.