The Scottish Government is hiring consultants to help it run the country's railways as an "operator of last resort" just weeks after threatening to strip ScotRail of its franchise.

The Government's transport agency said it was looking for technical experts to keep the trains running in case the current franchise was cut short.

READ MORE: Station protest to demand Abellio be stripped of ScotRail contract 

The "contingency planning" development is despite ministers previously telling Holyrood they already had measures in place to allow them to act as the operator of last resort, but did not expect to use them.

The Government said it was a "routine" replacement of a previous contract.

It comes just three weeks after the Transport Secretary warned ScotRail it could lose its contract if its recent poor performance, typified by delays and cancellations, continues.

Michael Matheson gave the firm two months to come up with a "remedial plan" to cut cancellations around Edinburgh.

He said if ScotRail failed to deliver on the plan, it would be classed as an event of default allowing ministers to "terminate the contract".

Nicola Sturgeon also said last month she wanted Holyrood to get powers to "nationalise our railways" after attacking ScotRail's poor performance.

The franchise has been held by the Dutch-owned firm Abellio since 2015.

It is due to hold it until 2025, although there is a break clause that could see it end in 2022.

Government agency Transport Scotland oversees the franchise on behalf of ministers, and also handles the Caledonian Sleeper franchise, which Serco is due to run until 2030.

READ MORE: Holyrood bosses criticised after spending £1000 on MSP piper's outfit 

The agency yesterday issued a £5m public sector contract notice for "strategic technical advisers" for its Rail Directorate during the 2019/2024 funding period.

It said experts were needed to "provide technical advice and suitable expertise to.. [the] rail franchise team in the event that either or both of the two rail franchises requires contingency planning options for an operator of last resort to be activated."

It said a further contract would cover "commercial and financial advisors for full operator of last resort services to Transport Scotland".

Transport Scotland also said it was looking for advice on "franchise contract management, including re-basing, re-letting, extension and termination", Network Rail projects, schedules, and the capacity of the ScotRail network.

Advice is also being sought on the trains, performance, staffing, fares and "passenger issues" of the current franchise holders.

The hunt is in spite of past assurances that last-resort steps were in place.

In October 2016, then transport minister Humza Yousaf told a Holyrood committee that if the franchise failed "the operator of last resort would end up being the Scottish ministers, and there are mechanisms in place to take the contract forward if it was terminated early".

He went on: "I can give people confidence that our railways would continue to run if the contract for the [ScotRail] franchise was terminated before it has run its due course.

"We have the option of using the operator of last resort, although I do not expect to be running our railways in the near future."

In a written parliamentary answer in 2016, Mr Yousaf also said ministers had "shelf companies ready to fulfil the operator in the event of an operator of last resort".

The last resort procedure is entirely separate from the SNP's plan for a public sector bidder which could run the ScotRail franchise after 2025. The UK Government has already used a holding company, Directly Operated Railways, to run the East Coast Main Line franchise after private operators repeatedly failed.

Labour MSP Colin Smyth said the SNP was "simply not serious" about public control of the railways.

He said: "Instead of empty promises and spin, rail passengers across Scotland need action. The Transport Secretary must use the upcoming break in the contract to remove Abellio ."

A Transport Scotland spokesperson said: “This is a routine contract notice which enables us to procure wide-ranging technical support that helps the delivery of our investment programme and statutory obligations.”