BARELY THREE months after a fertilizer-plant explosion in West, Tex., claimed 14 lives, a runaway train bearing crude oil derailed early Saturday morning, igniting a fireball that killed at least five people in a small Quebec town near the Maine border. Some 40 people from Lac-Mégantic are still missing, and much of the town — about 30 buildings — was incinerated.

The train, operated by the U.S.-owned Montreal Maine & Atlantic Railway Inc., had stopped for a routine crew change and inspection by an engineer, but then it started moving on its own, traveling nearly seven miles before it careened off the tracks. The crash remains under investigation, but one truth is already clear: There are real and oft-ignored dangers involved in the transfer of crude oil by rail.

In the midst of a boom in North American oil production, the amount of crude shipped by rail has skyrocketed. In 2008 9,500 carloads were shipped by rail, the Wall Street Journal reported; by 2012, that had soared to 234,000 carloads. On balance, the exploitation of new oil fields, like the growth in natural-gas production, has been a boon to the U.S. economy and foreign policy. But infrastructure has not kept pace. Particularly as political opposition has slowed pipeline construction, oil transport has had to rely on a network of railways, some of which are outdated and in need of repair. Investigators from Greenpeace found that some oil tank cars used in Canada and the United States were unsafe even 20 years ago. Along the same lines, in a 2009 report, the National Transportation Safety Board, investigating a derailment in Illinois, concluded that the outdated design of the cars was essentially a fuse waiting to be lit. A full report has yet to be released on the Lac-Mégantic disaster, but, as the New York Times has pointed out, it looks as though the cars in question were of that same model.

Environmentalists are pressing President Obama to deny TransCanada Corp.’s application to build the Keystone XL pipeline that would move bitumen (a heavy, oil-like substance) from Alberta to the Gulf of Mexico. Their chief objection is to the source of the oil, which they say cannot be extracted without more damage to the environment than occurs in typical oil drilling. But in their zeal to stop the project, they also have focused heavily on the supposed danger of oil pipelines.

The tragedy in Quebec is a reminder that no transportation method is without risk. Pipelines, properly built and maintained, offer the most secure, as well as most efficient, method. A gradual reduction of greenhouse gases is the right goal; as we’ve argued, the way to achieve it is through a carbon tax or, failing congressional action, the kind of regulations Mr. Obama recently proposed that would have the effect of weaning power plants off coal. The activists’ focus on Keystone represents a misordering of priorities.

Whatever happens with the pipeline, though, a lot of oil will continue to move by train. The accident in Lac-Mégantic should focus attention on the safety of the continent’s rails.