Preseli Pembrokeshire MP Stephen Crabb confirmed a breakthrough in the deal for the Murco plant had been made.
The future of the plant has been in doubt since owner Murphy Oil announced it was no longer buying crude oil to be processed at the site.
It followed the collapse of a Â£300m deal in April putting 400 jobs at risk.
The refinery has been a major employer at the port since it opened in 1973.
Mr Crabb told BBC Wales he was delighted with the timing of the deal.
"It was crucial to get this breakthrough this weekend because Murphy were clear that without that commitment, they were going to announce tomorrow morning they were beginning the process of shutting down the refinery altogether," he said.
He added that the buyer wants to keep the site as a refinery which would safeguard jobs.
"The sale will secure hundreds of high quality jobs and will enable the refinery to continue operating fully," Mr Crabb said.
"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.
"It has felt like a race against time to find a new buyer ever since Murphy started the clock on potential closure."
Although an agreement has yet to be finalised, it is understood the potential buyer is oil entrepreneur Gary Klesch.
The Switzerland-based Klesch Group specialises in the production and trading of chemicals, metals and oil.
The plant - which can produce 135,000 barrels a day, is currently not buying crude oil, but recycling oil products to keep it operational.
A spokesperson for Murphy Oil gave the proposed sale a cautious welcome.
They said: "Murphy feel that solid progress has been made in negotiations, but caution that substantial work remains to done.
"If the past has taught us anything, it is that these sales are especially challenging and we are not assured of success.
A Welsh government spokesperson said: "The plant is a vital part of the Welsh economy and we have been working tirelessly 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."
Hundreds of jobs at a closure-threatened oil refinery in Milford Haven could be saved after the sale of the site was agreed in principle.