A threatened oil refinery which supports hundreds of jobs in West Wales appears to have been saved after a buyout deal was sealed in principle.

The Murco refinery in Milford Haven has been up for sale for four years – and had been under a threat of closure after parent company Murphy Oil earmarked the loss-making facility for disposition earlier this year.

But Preseli Pembrokeshire MP Stephen Crabb, a Wales Office Minister, said an agreement in principle had been reached between Murphy and the sole remaining prospective buyer – believed to be oil entrepreneur Gary Klesch – and that more than 400 jobs connected to the refinery and its operations would be fully secured.

The Swiss-based Klesch Group, which Mr Klesch heads, specialises in the production and trading of chemicals, metals and oil. Due diligence will now be carried out before the deal can be confirmed.

Speculation had been growing for several months that Murphy were preparing to pull the plug if it couldn’t sell the site off, after it classified it as “discontinued” operations and said it expected “disposition” of the site in 2014 following a £63m loss in the last three months of last year.

Murphy then entered into consultation with staff over the closure of the site after talks with a private equity firm for a £300m takeover fell through.

That development led to the Welsh Government setting up a high-level task force to support Murco to find a buyer.

Profitability in its UK refining operations had been seriously squeezed due to a fall in the demand for petrol and intense competition from the US shale gas industry.

The Murco Oil Refinery in Milford Haven

Mr Crabb said: “I am delighted with the breakthrough today in negotiations over the sale of the Murco oil refinery in Milford Haven. The agreement in principle reached between Murphy and the buyer is a hugely positive step forward. The sale will secure hundreds of high quality jobs and will enable the refinery to continue operating fully.

“There remain challenges ahead, and a due diligence process to be completed, but I am just so pleased that we have reached this point. I am very optimistic that the sale can be completed.”

Mr Crabb, who was involved in bringing the parties to the negotiating table and was involved in brokering the deal, said the process had been a “race against time”.

He added: “All along I have been incredibly impressed with the dedication of the workforce on site who stayed focused despite the huge cloud of uncertainty hanging over the refinery.”

Lord Bourne, chair of the Haven Waterway enterprise zone, said the latest step was “extremely promising” and paid tribute to the work done by the UK and Welsh governments, unions and interested parties, but added: “It is very good news about this breakthrough, but there is a lot of work still to be done”.

Mid and West Labour AM Rebecca Evans said: “News of the agreement in principle is very encouraging. Murco is an extremely important employer for the area, supporting more than 400 skilled, well paid jobs.

“The prolonged period of uncertainty has been difficult for everyone concerned.

“I know the Welsh Government Economy Minister, Edwina Hart, will be leaving no stone unturned in trying to ensure a sale and save the jobs.”

A Welsh Government spokesman said: “The plant is a vital part of the Welsh economy and we have been working tirelessely to secure its future, working closely with the current owners, potential buyers and government at all levels.

“We remain committed to exploring every possible angle in supporting the company and the workforce.”