Cypriot politicians put the country's bailout deal back on track on a night of drama in Nicosia.
They quickly reversed their rejection of two pieces of legislation that international creditors demanded in return for a second 1.5 billion euro (£1.28 billion) instalment from a 10 billion euro loan.
In the late night re-vote, 41 politicians were in favour and only three against legislation pertaining to the supervision and reform of the country's troubled co-operative and commercial banks.
The two bills were part of a larger package of bailout measures that politicians were voting on ahead of a meeting of euro area leaders next week when it is expected that the instalment will receive the green light.
The legislation was a prerequisite for Cyprus' euro area partners and the International Monetary Fund to release the next instalment which will be used to restore co-operative banks' depleted capital buffers. In exchange for the cash support, the government would take ownership of nearly all of the co-operative banks' shares.
"Despite the problems of the political system and the mistakes and omissions of us all, politicians have demonstrated the responsibility that led to an agreement for the sake of what's best for our country," Averof Neophytou, leader of the ruling, centre-right DISY party told parliament.
Politicians had narrowly defeated the bills in a vote earlier amid disagreements over certain provisions of the legislation. Dissenting politicians, mainly from the communist-rooted, second largest AKEL party, worried that the bills would not prevent the selling off of co-operative bank shares to private investors.
Finance minister Harris Georgiades rushed to parliament to join party leaders in an emergency, late-night meeting that struck a compromise deal satisfying a key AKEL demand to enable co-operative banks to eventually buy back their shares and regain a level of autonomy. Politicians from AKEL and the smaller socialist EDEK party subsequently changed tack in the re-vote and approved the revised legislation.
No one expected the outcome of the first vote given the high stakes for the crisis-stricken country. But once the result was in, it sowed confusion within parliament and prompted speculation that Cyprus' 23 billion euro (£19.5 billion) financial rescue deal that it negotiated with its euro area partners and the IMF in March would be put into jeopardy. Another serious concern was that had the legislation not been approved immediately, depositors would rush once co-operative banks opened their doors to pull all their money out amid fears of their imminent collapse - something that would have put severe strain on the country's decimated banking sector.
As part of its rescue, Cyprus in March agreed on a deal that saw deposits over 100,000 euro in its two biggest banks take major losses. Second largest lender Laiki was shut down and folded into the bigger Bank of Cyprus which is undergoing major restructuring. Restrictions on withdrawals and transfers from banks were also imposed to prevent a run.