Spanish oil major Repsol came to the rescue of debt-laden shareholder Sacyr on Tuesday, buying 10 percent of its own shares for 2.57 billion euros ($3.35 billion) in a last-minute deal to help the builder refinance a loan. Had it not stepped in to buy the stock, Repsol faced the risk of creditor banks seizing control of Sacyr's 20 percent stake, creating further uncertainty over the future of the shares or forcing the builder into default. Sacyr, which builds everything from urban developments to hospitals and motorways, ran into trouble when it acquired 20 percent of Repsol just before the global financial crisis and collapse of Spain's construction bubble. The builder's banking syndicate had demanded it come up with about half of a 4.9 billion euro loan in order to refinance the remainder before a Wednesday deadline, but the builder struggled to find a third-party buyer at an attractive price. "We did not do this to make a profit. The possibility of Chapter 11 for Sacyr was not good news for our shareholders," a Repsol executive said on a conference call. Separately, Sacyr said it had agreed a three-year extension to pay back 2.4 billion euros of the loan after the stake sale. Shares in Sacyr, which were suspended before the market opened, were trading 8.0 percent higher at 4.44 euros by 1430 GMT. Repsol's shares resumed trade up 1.2 percent at 22.44 euros. "It is positive for Spain to keep Sacyr operational. Nobody wants to see companies going under at a time when the market is difficult enough," said Santander analyst Jason Kenney. Repsol said it would hold the shares, bought at 21.066 euros per share or a 5 percent discount to the market price, as treasury stock for a "very short time" before selling to an institutional or strategic investor or remunerating shareholders. Repsol currently holds less than 1 percent of its market capital as treasury stock. Repsol Chairman Antonio Brufau revealed the 10 percent stake purchase from Moscow, where he signed a deal to form an energy joint venture with mid-sized Moscow-based producer Alliance Oil. Sacyr will be in a less-threatening debt position following the Repsol stake purchase and refinancing agreement, but the deal has come at a price. The sale generated a net capital loss of 940 million euros. In addition, a source with knowledge of the refinancing deal said Sacyr must pay a 2.5 percent commission on the 2.4 billion euros it intends to refinance by January 31 2015 and a rate of 350 basis points over 3-month Euribor. Sacyr must also roll over 575 million euros of debt in 2012 and 952 million in 2013 in the face of scarce free cash flow due to Spain's prolonged construction downturn. Its ill-fated investment in Repsol led to a battle among management and shareholders which ended in the ousting of long-time chairman Luis del Rivero in October. Del Rivero stepped down from Repsol's board on Tuesday, and the future of Sacyr's other two board seats was still unclear. Following the sale of the Repsol stake, Sacyr said its shareholder pact with Mexico's Pemex had been broken. Pemex holds nearly 10 percent of Repsol, whose other main shareholder is Caixabank. Sacyr's banking syndicate was led by Bankia, Citigroup and Santander.