A US town narrowly escaped tragedy when a train carrying crude oil derailed and exploded nearby, its mayor says, and he is calling for changes in how the fuel is transported across the country.

No one was hurt in Monday's derailment that sent a huge fireball into the sky just outside Casselton.

The derailment in North Dakota, the country's No. 2 oil-producing state, happened amid heightened concerns about the United States' increased reliance on rail to carry crude oil.

Fears of catastrophic derailments rose after the July crash in a Quebec town of a runaway train carrying crude from North Dakota's Bakken oil patch. Forty-seven people died in the ensuing fire.

Most of Casselton's 2,400 residents obeyed a recommendation to evacuate their homes as strong winds blew potentially hazardous smoke toward the town overnight, Mayor Ed McConnell said Tuesday. Residents said the blasts endured for hours, shaking their homes and businesses.

BNSF Railway Co. spokeswoman Amy McBeth said another train carrying grain derailed first, and that knocked several cars of the oil train off adjoining tracks. BNSF said each train comprised more than 100 cars.

Rail tracks run through the middle of Casselton, and McConnell said it is time to "have a conversation" with federal lawmakers about the dangers of transporting oil by rail.

"There have been numerous derailments in this area," he told The Associated Press. "It's almost gotten to the point that it looks like not if we're going to have an accident, it's when."

Shipping oil by pipeline has to be a safer option, McConnell said.

The number of crude oil carloads hauled by US railroads surged from 10,840 in 2009 to a projected 400,000 this year. The rate of accidents has stayed relatively steady. Railroads say 99.997 per cent of hazardous materials shipments reach destinations safely.

National Transportation Safety Board officials on the scene Tuesday said an investigation would examine the train recorder, the signal system and the condition of the train operators, train and tracks.

Board member Robert Sumwalt said the tankers involved were DOT-111s, a model that has shown a tendency to rupture in other accidents, but he said it wasn't immediately clear if they were newer, safer DOT-111s or the older models.

Ron Ness, president of the North Dakota Petroleum Council, called the derailment "extremely unfortunate."

North Dakota oil drillers increasingly use trains to ship crude to locations not served by pipelines, in part because of the difficulty in securing permits for the structures, Ness said.