The westbound freight train derailed on the Ronkonkoma Branch just after 12:30 a.m.
Several of the wheels of the train were knocked off the tracks.
The derailment also caused about 500 gallons of fuel to spill.
Service was suspended for several hours between Farmingdale and Deer Park.
Train service was restored, and the delayed trains slowly made their way past the derailment.
Get Eyewitness News Delivered