Scottish ministers have resumed talks on the future of engineering business BiFab.
An agreement has been reached to prevent engineering business BiFab going into administration, the Scottish government has said.
First Minister Nicola Sturgeon and business minister Paul Wheelhouse have been speaking to managers at Seaway Heavy Lifting following a dispute with BiFab which led to cash-flow problems.
Talks have been held in Edinburgh between ministers and Dutch-based Seaway Heavy Lifting following a dispute with BiFab.
The company warned last weekend that it was in danger of going into administration.
An agreement will see BiFab receiving payments to alleviate the firm's "immediate cash flow issues".
BiFab employs 1,400 people at yards in Fife and Lewis.
The company employs 1,400 people at yards in Fife and Lewis.
'Anxious time'
BiFab warned last weekend that it was in danger of going into administration.
Economy Secretary Keith Brown said on Friday night: "Following a series of intensive talks over the course of Friday led by the first minister, myself and the minister for business, innovation and energy with Seaway Heavy Lifting, SSE, Siemens and the partners in the Beatrice Offshore Windfarm progress has been made and discussions will resume in the morning.
The deal means that work will continue on its current contract for the Beatrice Offshore Windfarm.
"We are also in dialogue with the trade unions and BiFab. Ministers will continue talks for as long as necessary to avert the risk of administration at BiFab.
A financial package has been provided by Seaway Heavy Lifting, SSE and windfarm partners JCE Offshore, ministers said.
"We are very much aware that this will be an anxious time for the people employed at BiFab, as well as their families and the wider communities of Burntisland, Methil and Arnish and Ministers will continue to do all we can to secure a positive resolution.
The Scottish government has also indicated it would loan money to BiFab if required.
"We hope to be able to provide more clarity on the situation in the near future."
First Minister Nicola Sturgeon said: "I am pleased that after an extensive series of talks over the last week and two days of intense negotiations we have been able to broker a commercial agreement that lifts the threat of administration from BiFab and allows work on the current contract to continue.
"In particular I welcome the moves made by Seaway Heavy Lifting, SSE and the partners in the Beatrice Project, JCE Offshore and Siemens to resolve this situation and enable BiFab to continue its work on this contract."
Ms Sturgeon said all companies involved in the negotiations had taken "difficult decisions" to secure the outcome.
She added: "While this deal lifts the immediate threat of administration, we recognise that there is a lot of work still to do to secure the long term position.
"Ministers will continue to work with BiFab, the trade unions and industry partners to identify ways to secure the long term future of renewables manufacturing on these sites."
'Dignity and determination'
Representatives of the workforce at BiFab's two yards - at Arnish on Lewis and Burntisland in Fife - this week held a demonstration outside the Scottish parliament.
Representatives of the workforce at BiFab's two yards - at Arnish on Lewis and Burntisland in Fife - this week held a demonstration outside the Scottish parliament.
Work-in
Many of the employees had agreed to work without pay at the yards in the hope of allowing a rescue deal to be put in place.
Many of the employees are continuing to work without pay at the yards in the hope of allowing a rescue deal to be put in place.
Union leaders from Unite and GMB have praised the Scottish government for its role in brokering the deal.
Mr Brown told BBC Scotland earlier: "There's one particular payment which has not been paid and the two different parties to that payment - on the one hand BiFab on the other hand Seaway Heavy Lifting - have different views on the nature of that payment and when it should be made."
In a joint statement, Unite's Pat Rafferty and GMB's Gary Smith said: "Make no mistake these yards would be closed today if it wasn't for the dignity and determination of the workers and their families in Fife and Lewis to save their jobs and industry.
He said the Scottish government's role is to encourage a resolution of that dispute.
"With their futures on a knife edge they worked for nothing, stayed strong and resolute and by staying united they have won their future.
"What we're trying to do is bring the parties round the table," he said.
"Further, the Scottish government said they would leave no stone unturned and their efforts have been pivotal in bringing BiFab back from the brink."
As the ministerial talks continued, union officials have been at Arnish to talk to workers there.
They formally agreed to back a work-in until the future of the yard becomes clear.
Alan Ritchie from the GMB said: "The workers have passed a resolution in line with the workers in Fife.
"They have decided that they will work as in a work-in. They have also decided that... nothing will come in the yard, nothing will go out the yard, without the permission of the shop stewards committee."
Western Isles local authority Comhairle nan Eilean Siar said it stood ready to support and assist workers.
'Constructive talks'
Council leader Roddie Mackay said: "Any loss of jobs would a significant blow to the local economy and it is critical that the government and other stakeholders in the supply chain to bring new money to the table to help sustain the company."
Also represented at the ministerial talks are Scottish Enterprise, Siemens and SSE - which has a trading relationship with BiFab and owns a stake in the business.
An SSE spokesman said: "SSE continues to engage closely with BiFab's management, SHL, the Scottish government and other stakeholders to find a sustainable solution for the company.
"This engagement has included constructive talks today chaired by the first minister.
"As a minority shareholder in BiFab and a partner in Beatrice Offshore Wind Limited, SSE is willing to play its part in a recovery package supported by and involving all stakeholders."