Newly released documents show the government forced KiwiRail to backtrack on its decision to ditch the electric locomotives on the North Island's main trunk line.
According to the Treasury, it's the first time a state-owned enterprise has been directed by a minister to make a decision that didn't stack up commercially.
The State-Owned Enterprises Act said an entity's principle objective was to be a successful business.
In 2016, KiwiRail's board decided to replace its 15 electric locomotives with diesel, arguing it would make the company more efficient and better able to take freight, and with less freight going by road, there'd be a positive environmental impact.
On 30 October last year the government put a stop to the plan instead promising a $35 million cash injection to refurbish the electric locomotives.
In a letter to Transport Minister Phil Twyford two weeks before the decision was announced, acting chief executive Todd Moyle made it clear KiwiRail didn't have the money to refurbish the locomotives.
"KiwiRail has no funding for these additional costs and is unable to recoup the investment and there is no uplift in revenue associated with this decision," he wrote.
But a Cabinet minute written the day before the government's announcement, showed Cabinet agreed to use its powers under the State Owned Enterprises Act to direct the company to provide a non-commercial service.
Mr Twyford said being a successful SOE was more than just about profit and loss for a particular year, and this government wanted to grow rail.
He said previous governments had left KiwiRail on financial life support with no future vision.
"That's not how our government sees it, we're committed to bringing rail into the heart of the transport system, instead of treating it as the poor cousin and drip-feeding it a little bit of money year after year and barely keeping it alive," he said.
KiwiRail uses electric locomotives on the main trunk line between Hamilton and Palmerston North.
When it said it was going to switch to diesel, the Rail and Maritime Transport Union accused it of "environmental terrorism".
The union's general secretary Wayne Butson said the decision to go down the diesel track was the best case of reverse engineering he'd ever seen.
"What you started with as your opening premise was the decision that they wanted to have and then they just worked backwards, and they screwed the scrum, massaged the logic and the numbers", he said.
He said at that time KiwiRail's board were wedded to a philosophy of simplify and standardise.
"There was this mantra which said 'we only wanted one type of wagon, we only want one type of loco and that will give us immeasurable gains over time. It will reduce the inventory that we need, in terms of spares that we need for things'. In my view it didn't have any logic," he said.
Mr Butson said that decision failed to consider the needs of a modern railway, which must have some level of variation in the types of locomotives and wagons it uses.
Engineer Roger Blakeley said the decision to scrap the electrics was at odds with the Labour government's target of getting to net zero carbon emissions by 2050 and leader Jacinda Ardern's claim that climate change was her generation's "nuclear free moment".
"With the diesel locomotives, if KiwiRail went ahead with them, it would burn an extra 8 million litres of diesel fuel per year and add around 12,000 tonnes of carbon dioxide to the atmosphere each year. That's what would have been the implications of a switch back to diesels," he said.
The Palmerston North to Hamilton route was electrified in the 1980s and the plan then was to carry on and electrify the whole main trunk line from Wellington to Auckland.
It's estimated completing the project now would cost around a billion dollars.
Mr Twyford said it's not part of the government's immediate work programme.