At least 21 train cars ran off the tracks in Kentucky Thursday when a conductor was forced to slam on the brakes to avoid crashing into a semi-truck stuck on the tracks.

The CSX train toppled over around 3 p.m. in the heart of downtown Glendale, a community roughly 50 miles south of Louisville, a company spokesperson told The Post.

The train “went into emergency attempting to avoid a collision with a semi-truck and trailer stuck on the crossing,” the spokesperson said.

The sudden stop forced 21 cars to run off the tracks and land within spitting distance of nearby homes and buildings.

Though the train succeeded in avoiding the semi-truck, one of the derailed cars collided with another vehicle that was near the tracks.

One woman inside the car sustained minor, non-life-threatening injuries, a Kentucky state police officer said.

The train was not carrying hazardous materials — police said it was hauling other vehicles southbound when it derailed.

At least 21 CSX train cars ran off the tracks in Glendale, Kentucky.

Train lies on the ground near the tracks.
The conductor slammed on the brakes to avoid hitting a semi-truck stuck on the tracks.

Thursday’s derailment is the second for CSX in eight days.

All four locomotives and 22 empty cars on the company’s 109-car train derailed after hitting a massive boulder lodged in a West Virginia track last week.

Several of the cars dropped into the riverbed below, spilling an unknown amount of oil and diesel fuel into the water.

Train lies on the ground near the tracks.
One of the derailed cars swung around and hit a woman sitting in a nearby vehicle.

Train lies on the ground near the tracks.
The cars crashed on the ground near buildings off the tracks.

Washington state and Arizona also saw train derailments Thursday.

About 5,000 gallons of diesel fuel spilled onto the ground on the Swinomish tribal reservation in Washington after a BNSF train ran off a berm.

Eight BNSF cars carrying corn syrup derailed in western Arizona, near the state’s border with California and Nevada, though no spills were reported.

No injuries were reported. It wasn’t clear what caused either derailment.

With Post wires