ST. PAUL, Minn. — In the wake of fiery derailments in Canada and North Dakota, Minnesota Gov. Mark Dayton on Tuesday signed into law a measure requiring railroad and oil pipeline companies operating in the state to help pay for training and programs to prepare for emergencies.

The law empowers the state to collect a total of $2.5 million annually from railroad and oil pipeline companies until July 1, 2017. That money will help first responders get ready for derailments and spills involving oil and other hazardous substances.

That news is a relief to Scott Braith, chief of the volunteer fire department in Staples, Minnesota, a town of about 2,900 on a major freight line which sees 70 to 100 trains a day, some carrying crude oil from North Dakota's Bakken shale fields.

"This new legislation requires them to contact us directly and do onsite training," said Braith, who commands 25 firefighters. "That is what we are looking for."

The law provides for new safety measures that include $2 million for at-grade crossing improvements such as gates and signals, the addition of three more rail-safety inspectors — which railroad companies also will pay for by providing about $936,000 over three years — a one-time $1.6 million expenditure for other rail and pipeline safety actions, and increased lighting in areas where trains with more than 25 tanks of hazardous material are assembled and dissembled.

Minnesota now has only one rail inspector for the entire state, so the new law will bring that number to four.

The law also requires railroad personnel be available at least by phone within one hour of an accident, and be on scene within three hours to assist with local emergency response efforts. The legislation does not require a comparable response by oil pipeline companies, an omission that disappointed Dayton. He said he would fight to put the oil pipeline company accident response on par with railroads next year.

The legislation follows the explosion last year of a train carrying Bakken crude oil in Lac-Megantic, Quebec, that killed 47 people, and another close call near Casselton, North Dakota.

Six to eight oil-tank trains travel through Minnesota every day. Two companies run them, Burlington Northern Santa Fe Corp., headquartered in Fort Worth, Texas, and Canadian Pacific, based in Calgary, Alberta, Canada.

In response to the new Minnesota fee, Canadian Pacific spokesman Ed Greenberg said the company continued to review aspects of the legislation.

BNSF spokeswoman Amy McBeth did not directly address the fee, but said the railroad is committed to partnering with local emergency officials.