A House-Senate conference committee had been deadlocked for several days about the proposal, but finally decided to resolve differences and fund the $523,000 program that includes two rail safety inspectors.
Senators voted 47-0 to adopt the conference committee compromise Monday, while the House endorsed it 85-4 hours later.
The program is part of the Public Service Commission's $22.2 million budget.
The Public Service Commission had requested $972,000 in the next two-year budget cycle to fund the program consisting of two rail safety inspectors and a rail safety manager to supplement inspections by the Federal Railroad Administration.
The program had been a campaign platform for Republican Public Service Commissioner Julie Fedorchak when she ran for the position last year. GOP Gov. Jack Dalrymple also had included the funding for the program in his budget to help prevent oil train accidents, like one in his hometown of Casselton that left an ominous cloud over the city and led some residents to evacuate.
But House budget writers stripped the funding earlier this month, with many Republicans saying it's not needed and that it duplicates the federal government's efforts.
Democrats blasted the move, calling it a broken promise.
The legislation worked out by House and Senate negotiators will fund a full-time rail inspector and one temporary rail inspector. It also requires railroads offer training to fire departments located along oil train routes.
"It isn't all that we wanted, but it's a good start," said Fargo Republican Sen. Ronald Sorvaag, the conference committee chairman.
GOP Rep. Roscoe Streyle from Minot said federal inspections have increased in the region and railroads have invested hundreds of millions of dollars to ensure rail lines are safe, including carrying out additional maintenance.
"Nobody wants these to go off the tracks," he said.
The pilot program is to be in place four years, although lawmakers have only funded it for two.
Sen. Tyler Axness, a Fargo Democrat, said cutting the number of rail inspectors from three to two was irresponsible. He said lawmakers who did not support the original bill "aren't willing to do whatever it takes to protect our communities."
Axness was the first to propose the rail safety program in his failed bid against Fedorchak for a PSC seat in November.
Fedorchak has said the Federal Railroad Administration has fewer than a dozen employees in North Dakota. Only two are rail inspectors, who also inspect tracks in Montana and South Dakota.
The PSC has said rail traffic increased in North Dakota by 233 percent between 2000 and 2012 due to the state's oil boom. In the last five years, the commission says, the state has seen more than 75 accidents related to track and equipment problems, resulting in more than $30 million worth of damage.