Bakery Warburtons says it is selling its threatened Newport factory to valleys-based firm Brace's Bakery.
The Lancashire-based company had said in September that the site might have to shut with 114 job losses due to surplus capacity.
Crumlin-based Brace's told unions and the assembly government it was interested in taking over the site.
Warburtons said: "Both companies will be working towards completing the sale and transfer as soon as possible."
It added: "We will now enter a period of due diligence with the aim of concluding the sale and managing the transfer of the bakery and its employees to Brace's.
"Our main aim over the next few weeks will be to conclude the sale, and keep our employees fully informed and consulted on progress."
The site at Rogerstone in Newport, which opened in 2006, produces 450,000 products every week with a range of white, wholemeal and fruit loaves.
Brace's already employs 350 people at two sites near Crumlin. The 114 people who work for Warburtons will be transferred to Brace's.
In a statement, Brace's said it was "thrilled" that Warburtons had accepted the offer and that the move was key to its future growth.