The collision occurred on the rail line linking Le Brassus and Vallorbe at around 10.20am, cantonal police said in a news release.
The victims, citizens of Bosnia-Herzegovina aged 46 and 45, were in a car that traversed the barrier-free Rocheray crossing just as the train was passing through, police said.
For an undetermined reason, the driver of the car ignored the crossing lights and failed to see the train, operated by the Travys public transport company and heading toward Vallorbe.
The train struck the car with a force that propelled it a dozen metres in the air, police said.
The car landed against a electric transmission line pylon.
One of the men was thrown out of the car while the other was trapped, but both were dead by the time rescue officials arrived, police said.
None of the nine passengers aboard the three-carriage train were injured.
However, police said the train driver was taken to a nearby hospital for psychological support.
Travys pressed shuttle buses into service to keep the public transport link operating between Vallorbe and Le Brassus for the rest of the day.
An investigation into the cause of the accident is under way, led by police officers from the traffic division.