ABC News December 27, 2018

Dash cam shows Illinois police officer swerve off the road to avoid being hit by speeding train

WATCH: Police officer nearly struck by commuter train

Police officer Peter Staglewicz narrowly avoided tragedy last month when he swerved off the road just feet from being slammed into by a speeding commuter train.

Staglewicz, who works for the police department in Mokena, Illinois, was driving toward the train crossing when heart-stopping video from his dash camera showed him swerve left into a traffic island just to avoid likely tragedy.

The video was posted on Staglewicz's Facebook page last Friday though it happened in November. The clip had garnered over 640,000 views on his page in six days.

Mokena Police Department
A police officer in Mokena, Ill., narrowly avoided tragedy when he swerved to avoid being hit by a commuter train due to a technical malfunction in November 2018.
(MORE: Manhunt underway after suspected gunman kills officer during traffic stop in Northern California)

In the video, Staglewicz can be seen driving up to the tracks with the crossing gate still raised. The lights start flashing and the gate drops only seconds before the train blows through the intersection.

Metra, which operates commuter trains in the Chicago area, blamed the near-miss on a mechanical issue. It was remedied a few hours later, Metra told Chicago ABC station WLS.

Mokena Police Department
A police officer in Mokena, Ill., narrowly avoided tragedy when he swerved to avoid being hit by a commuter train due to a technical malfunction in November 2018.
(MORE: Firefighter, 21, dies in Christmas crash while responding to call)

"Throughout my life, I've had very little luck," Staglewicz wrote on Facebook. "I've bought tons of raffle tickets, from little league tickets to charity raffles. Every lottery ticket was a loser. I just thought I wasn't born with luck at all. Little did I know, I had luck, I was just saving it all up for the perfect time.

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

Another car just managed to safely make it through the intersection ahead of Staglewicz's cruiser.

Mokena Police Department
A police officer in Mokena, Ill., narrowly avoided tragedy when he swerved to avoid being hit by a commuter train due to a technical malfunction in November 2018.
(MORE: Chicago police gather to mourn young officer struck, killed by train)

Two Chicago police officers were killed when they were struck by a train earlier this month, though that incident actually took place after Staglewicz's close call.

Eduardo Marmolejo, 36, and Conrad Gary, 31, both died at the scene while they were pursuing a suspect involved in a shooting. Authorities believe a train heading in the opposite direction may have masked the sound of the one that struck the officers.