An Illinois police officer's dashboard camera captured his near-miss with a passing train at a crossing where the gate malfunctioned.

Mokena Police Department Officer Peter Stanglewicz posted a video to Facebook showing the moment he was able to swerve before ending up directly in the path of a Metra train in Mokena.

"Here is all my luck being used ALL AT ONCE. If I never win anything again, I'm perfectly fine with that," Stanglewicz wrote.

Metra officials said an equipment malfunction at the 191st Street crossing caused the warning lights and crossing gates to not be triggered until the train had already arrived. They said the equipment was repaired a few hours after the incident.