Two Suffolk officers, Christopher Palazzo and Jereme Matthews, were on routine patrol and happened to arrive at the crossing just as the 911 calls were going out, police said.
As Foulke tried in vain to free the vehicle from the tracks, police said they attempted to contact the railroad to stop the train.
When that failed, Palazzo and Matthews quickly cleared the area and pulled Foulke from the car, police said.
Moments later, as the officers and Foulke ran to safety, the train smashed into the Jetta, sending it "flying across the tracks," according to police.
No one was injured on the train or in the immediate vicinity, police said.
Foulke was to be arraigned Saturday in First District Court in Central Islip.
Trains on the Montauk line were suspended after the crash eastbound until 6:25 p.m. and westbound until shortly after 7.
The train involved in the crash was able to continue on to its destination after a delay of about an hour and 40 minutes, the railroad said.