SANTA CLARITA, Calif. — An entire tree fell onto a roller coaster’s tracks in California, dislodging the front car and keeping nearly two dozen riders hanging 20 to 30 feet in the air for hours, according to the state agency that investigates workplace accidents.It took nearly three hours for all 22 of the stranded riders to be rescued Monday night. Four people were hurt and two were taken to the hospital as a precaution, but all the injuries were minor, fire and park officials said. “We were going across one turn and all of a sudden a loud noise happened,” Jeremy Ead, one of the injured riders, told KCAL-TV. “I ducked down just in time. A hard branch hit me in the head. I was there bleeding from my head, which was a little worse than this,” he said, pointing to a gash on his forehead. Initial reports suggested it was a branch that fell, but Peter Melton, a spokesman for California’s Division of Occupational Safety and Health, said Tuesday the whole tree came crashing down. An overhead photograph showed the trunk resting on the tracks. The Ninja coaster at Six Flags Magic Mountain will remain closed until investigators determine exactly what went wrong, said Melton. His agency would have to sign off before it is returned to service, he said. The coaster stopped abruptly at about 5:30 p.m., said Michael Pittman, a Los Angeles County Fire Department dispatch supervisor. At least one of the cars, which are normally suspended beneath the track, was dangling at an angle, derailed at the front. Firefighters and park maintenance workers removed the riders one by one through a tangle of track and trees. Six Flags Magic Mountain, located 25 miles north of Los Angeles, is owned by Grand Prairie-based Six Flags Entertainment, the owner of Six Flags Over Texas and Hurricane Harbor in Arlington. Six Flags shares (ticker: SIX) closed down 8 cents at $42.02.The park’s website advertises that the Ninja swoops through the trees to give riders a thrill. “As you shoot down the snake-like steel track you’ll grip the hillsides and blast through the trees swiftly, slicing through the landscape,” the online description says. “Ninja pivots with precision as you narrowly miss tagging land and water, whipping around at 55 miles per hour.” Calls and emails Tuesday seeking comment from Six Flags officials were not immediately returned. The accident comes just over a week after dozens of people were stranded more than 200 feet up on a revolving tower at SeaWorld San Diego for hours. Authorities there said a power failure stalled the ride. In July of 2013, a woman was ejected from a roller coaster at Six Flags Over Texas in Arlington and died. The death was ruled an accident, but her family has sued both Six Flags and the German company that built the coaster’s trains, both of whom denied any wrongdoing.