At least 24 people were hurt and hundreds were evacuated after two subway trains collided on the Upper West Side Thursday afternoon, causing both to derail, officials said.

A northbound 1 train with up to 500 passengers was pulling out of the 96th Street station shortly after 3 p.m. when it collided with another disabled 1 train and both derailed, police sources said.

The disabled train was being worked on due to vandalism after someone went through the train pulling the emergency brake cords in several cars, MTA officials said.

Four MTA workers were on board trying to reset the brakes at the time — but no customers.

Officials confirmed that at least 24 people suffered minor injuries and were taken to local hospitals.

“Fortunately, nobody was seriously injured. The injuries that were sustained were consistent with a low-speed train derailment,” FDNY Deputy Assistant Chief Ian Swords told reporters outside of the train station Thursday night.

The passenger train, which did not completely exit the station, was evacuated via the station platform, officials said.

About 300 to 400 additional passengers were also evacuated from a train that was not involved but stuck behind the collision after power was shut down. The passengers got off through the train that had derailed, officials said.

Rich Davey, president of the MTA, said there is nothing to suggest the crash was equipment-related and are investigating any human factors that could have caused it.

“The equipment was working as intended,” he said of the switches and signals.

“Obviously, two trains should not be bumping into one another,” he said. “We are going to get to the bottom of that.”

The passenger train was diverted to the express track to get around the dead train at the 96th Street station. The switch back to the local track is just north of the station, the MTA said.

As the train switched over from the express track, the stuck train began moving again for unknown reasons and the two front cars hit each other, causing both to derail, transit officials said.

Jaime Levy’s “rattled” 15-year-old daughter Tamar was stuck on a 2 train for more than an hour after the collision.

Her daughter told her passengers desperate to exit the subway took matters into their own hands.

“This train derailed. My daughter has been stuck for an hour and a half in between tracks on the express. People are climbing out of the windows and crossing the local track and then climbing up. She won’t do that, obviously,” Levy told The Post at the scene as she waited for her daughter.

“She’s in between stations so she’s close enough,” she added.

Another passenger described similar chaos.

“There were people getting off the train and running on the rails,” said a straphanger who was stuck on a train for an hour after it was struck behind the crash site.

The MTA warned straphangers that 1, 2 and 3 train service could be disrupted and delayed in Manhattan through Friday morning as they re-rail the trains and inspect the rails and tunnel.

The A/C and B/D train lines would be the most likely alternatives for commuters.

“It’s going to take us a while to get this service back and running. We have crews down there now and I expect we’ll be out there all night,” Davey said.

“My hope is we will have service tomorrow for rush hour, but I cannot guarantee that,” he added.