The Almaraz plant in Western Spain hosts the first two nuclear reactors slated for closure in a calendar which foresees all seven in the country going offline between 2027 and 2035.

Phasing out nuclear power, which provides about a fifth of Spain's electricity, is part of a package of energy market proposals that was one of the last initiatives of the Socialist government before parliament was dissolved before a general election next month.

A disagreement between Almaraz's owners, Iberdrola, Endesa and Naturgy, over how much to invest to keep the plant running rumbled on close to a March 31 licence renewal deadline, putting the plant at risk of an earlier closure.

The firms will now apply to keep the site's two reactors running until 2027 and 2028 respectively, on condition they will spend no more than 600 million euros (517 million pounds) in total on the units, three sources with knowledge of the talks said.

If the bill were to exceed this amount, the owners would have to meet again to discuss what to do, the sources said.

Endesa had resisted adding any spending limits to a protocol signed last week setting out the closure dates, but a spokesman for the company said it was pleased with the deal.

"We are very satisfied with the agreement because it fulfils the protocol signed last week which allows the plants to keep operating," the spokesman said.

The spokesman added that the agreement also applied to two other nuclear power stations in which it holds majority stakes, whose licences likewise need renewing.

Iberdrola, which owns 53 percent of the plant, said in a statement the Almaraz agreement ensured it could convene talks among shareholders to make decisions if the plant's financial outlook were to change.

Iberdrola added that the process of dismantling the plant would ensure economic activity and employment in the local area for up to 15 years after its closure.

Naturgy declined to comment.

Shares in Endesa, which is controlled by Europe's biggest utility Enel, led gainers on a broadly negative Spanish blue-chip index [.IBEX] on Friday, albeit up only a slim 0.8 percent on the day by 1607 GMT.

Iberdrola stock fell 0.7 percent and Naturgy shed 0.5 percent.

Endesa, whose 36 percent stake makes it the second-biggest shareholder, suggested this week that the other two firms transfer their stakes to it free of charge, one of the sources with knowledge of the talks said.

Asked by reporters about this offer on Thursday, Endesa Chief Executive Jose Bogas said he did not think it was the right course of action but added: "All possibilities are open."

(Reporting by Isla Binnie; Editing by Kirsten Donovan and Edmund Blair)

By Isla Binnie