Eight cars of the Pan Am Railways freight train came off the track around 11 a.m., Lawrence firefighter Chad Nickerson told the Boston Globe.
The four cars at the front of the train and two locomotives at the back stayed on the tracks.
Deputy Fire Chief John McInnis said no one was injured in the accident and no hazardous materials were spilled.
McInnis said it should take about 24 hours for the train cars to be put back on the track. It caused the Haverhill commuter rail line to be delayed for a short time.
Officials are investigating the cause of the accident.